Is there a `pointer-events:hoverOnly` or similar in CSS?
I don't think it's possible to achieve your aims in CSS alone. However, as other contributors have mentioned, it's easy enough to do in JQuery. Here's how I've done it:
HTML
<div
id="toplayer"
class="layer"
style="
z-index: 20;
pointer-events: none;
background-color: white;
display: none;
"
>
Top layer
</div>
<div id="bottomlayer" class="layer" style="z-index: 10">Bottom layer</div>
CSS (unchanged)
.layer {
position:absolute;
top:0px;
left:0px;
height:400px;
width:400px;
}
JQuery
$(document).ready(function(){
$("#bottomlayer").hover(
function() {
$("#toplayer").css("display", "block");
},
function() {
$("#toplayer").css("display", "none");
}
);
});
Here's the JSFiddle: http://www.jsfiddle.net/ReZ9M
Remove click function, but keep hover intact
Add pointer-events: none
to the a
element, then apply the hover to the parent element, targeting the a
specifically within that:
span a { pointer-events:none;}
span:hover a { color: red;}
<span><a href="#">Hello, world!</a></span>
Css pointer-events hover issue
This happens because when you set the class having pointer-events: none
it triggers a mouse leave event, hence it flashes.
First of all, may I suggest you use :hover
, second, whether you use :hover
or script, you need to target the specific element that shouldn't be clickable, for example the span
.playlist-non-selected:hover span {
pointer-events: none;
}
Stack snippet
.playlist-item { position: relative; top: 0px; left: 0px; height: 40px; margin-bottom: 5px; overflow: hidden; line-height: 40px;}.playlist-title { display: inline-block; position: relative; top: 0px; margin-left: 20px; overflow: hidden; font-size: 22px; font-family: 'Gnuolane Free'; margin-bottom: 0px;}.playlist-non-selected { color: #bbb;}.playlist-non-selected:hover{ color: red;}.playlist-non-selected:hover span{ pointer-events: none;}
<div class="playlist-item"> <a class="playlist-non-selected" href="#"> <span class="playlist-title">AudioAgent - Japanese Intro</span> </a></div>
CSS :hover on SVG group area instead of rendered pixels, pointer-events: bounding-box not working cross browser. How to workaround
So pointer-events: bounding-box
seems to not be supported by most browsers.
I implemented the workaround @ccprog suggested on the comments section of my question.
I added a <rect fill="none">
element to svg, that is same dimensions than the SVG itself. I added a :hover
selector for that element and sibling selector ~
to select its sibling group with the flip
class inside.
See CSS:
#mobile-hover {
visibility: visible;
pointer-events: visible;
}
#mobile-hover:hover ~ .group .flip {
-moz-transform-origin:55% 50%;
-webkit-transform-origin: 55% 50%;
transform-origin:55% 50%;
-webkit-animation: flip_left 1.6s forwards;
animation: flip_left 1.6s forwards;
}
I found out I had to add pointer-events: visible
to the rect
element so it would detect the :hover
. I added visibility: visible
as a requirement to pointer-events: visible
to work.
Below the full new SVG code:
<?xml version="1.0" encoding="UTF-8"?>
<svg width="40px" height="40px" viewBox="0 0 40 40" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" id="mobile-icon">
<style>
#mobile-hover {
visibility: visible;
pointer-events: visible;
}
#mobile-hover:hover ~ .group .flip {
-moz-transform-origin:55% 50%;
-webkit-transform-origin: 55% 50%;
transform-origin:55% 50%;
-webkit-animation: flip_left 1.6s forwards;
animation: flip_left 1.6s forwards;
}
@keyframes flip_left {
0% {transform: perspective(2000px) rotateY(90deg) skewY(-1deg)}
30% {transform:perspective(2000px) rotateY(-25deg) skewY(-0.8deg)}
50% {transform:perspective(2000px) rotateY(20deg) skewY(0.8deg)}
70% {transform:perspective(2000px) rotateY(-10deg) skewY(-0.8deg)}
100% {transform:perspective(2000px) rotateY(0deg)}
}
</style>
<!-- Generator: Sketch 51.2 (57519) - http://www.bohemiancoding.com/sketch -->
<title>Mobile solutions</title>
<desc>Created with Sketch.</desc>
<defs></defs>
<g id="mobile" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" >
<rect fill="none" width="40" height="40" id="mobile-hover">
</rect>
<g id="MS_HP_Usecase_Based_Page-Desktop-2A" transform="translate(-766.000000, -418.000000)" stroke="#00A0DF" stroke-width="1.25" class="group">
<g id="Asset-5" transform="translate(766.000000, 418.000000)">
<g class="flip">
<rect id="Rectangle-path" stroke-linecap="round" stroke-linejoin="round" x="12.35" y="7.41" width="15.32" height="25.33" rx="2.03"></rect>
<circle id="Oval" stroke-linecap="round" stroke-linejoin="round" cx="20.01" cy="28.72" r="1.58"></circle>
<path d="M18.43,10.72 L21.48,10.72" id="Shape" stroke-linecap="round" stroke-linejoin="round"></path>
</g>
<circle id="Oval" cx="19.67" cy="19.67" r="19.04"></circle>
</g>
</g>
</g>
</svg>
Works on Chrome, Safari and Firefox and I'm attempting to test IE11 and Edge next.
Many thanks,
Related Topics
Firefox 30 Is Not Hiding Select Box Arrows Anymore
How to Apply Font Anti-Alias Effects in CSS
Flexbox, Z-Index & Position: Static: Why Isn't It Working
Ajax HTML Vs Xml/JSON Responses - Performance or Other Reasons
How to Make a Table with Equal Column Widths in CSS
CSS - Make Div's Inherit a Height
Square Div Where Height Is Equal to Viewport
Include HTML Files in R Markdown File
Ckeditor Strips Inline Attributes
Why Does an Anchor Tag's Href Values Need Http:// Preprended to The Url
Scrolling to an Anchor Using Transition/CSS3
CSS Box Shadow Around a Custom Shape
How to Set The <Img> Tag with Basic Authentication
@Font-Face Not Working with Specific Version of Internet Explorer 11
Why Does CSS Grid Layout Add Extra Gaps Between Cells