[英]Cancel hover when hovering over seperator
I want to change the image when I hover on the button, but it may not change when I hover on "separator" in the jsfiddle below. 当我将鼠标悬停在按钮上时,我想更改图像,但是当我将鼠标悬停在下面的jsfiddle中的“分隔符”上时,它可能不会更改。
I don't want to use js 我不想使用js
html: 的HTML:
<div id="my-thumbnail-link" class="vcenter-parent">
<img class="vcenter-child">
SEPERATOR
<a href="#potato" class="vcenter-child">Some Link</a>
</div>
CSS: CSS:
.vcenter-parent {
display: flex;
justify-content: center;
}
.vcenter-child {
align-self: center;
}
#my-thumbnail-link {
}
#my-thumbnail-link img { /* Select all img tag inside div */
background: url("img") no-repeat;
width: 32px;
height: 32px;
}
#my-thumbnail-link:hover img { /* Select all img tag inside div when it is hovered */
background: url("img1") no-repeat;
}
#my-thumbnail-link a { /* Select all a tag inside div */
color: gray;
}
#my-thumbnail-link:hover a { /* Select all a tag inside div when it is hovered */
color: blue;
font-weight: bold;
}
https://jsfiddle.net/srerd881/ https://jsfiddle.net/srerd881/
You could use the pointer-events
property. 您可以使用
pointer-events
属性。
Apply none
to the wrapper. 不对包装纸应用
none
。
Then apply auto
to the img
and the a
. 然后将
auto
应用于img
和a
。
Note: According to caniuse pointer-events
has good support, however you should note this line: 注意:根据caniuse,
pointer-events
具有良好的支持,但是您应该注意以下行:
Does not work on links in IE11 and Edge unless display is set to block or inline-block.
除非将显示设置为阻止或行内阻止,否则在IE11和Edge中的链接上不起作用。
You may need to make some adjustments depending on your needs. 您可能需要根据需要进行一些调整。
.vcenter-parent { display: flex; justify-content: center; } .vcenter-child { align-self: center; } #my-thumbnail-link img { /* Select all img tag inside div */ background: url("https://unsplash.it/40") no-repeat; width: 32px; height: 32px; } #my-thumbnail-link:hover img { /* Select all img tag inside div when it is hovered */ background: url("https://unsplash.it/50") no-repeat; } #my-thumbnail-link a { /* Select all a tag inside div */ color: gray; } #my-thumbnail-link:hover a { /* Select all a tag inside div when it is hovered */ color: blue; font-weight: bold; } #my-thumbnail-link { pointer-events: none; } #my-thumbnail-link img, #my-thumbnail-link a { pointer-events: auto; }
<div id="my-thumbnail-link" class="vcenter-parent"> <img class="vcenter-child"> SEPERATOR <a href="#potato" class="vcenter-child">Some Link</a> </div>
EDIT 编辑
As pointed out by Bram Vanroy in comments, an img
with no src
tag will not validate. 正如Bram Vanroy在评论中所指出的那样,没有
src
标签的img
将无法验证。 To use the background-image
property, an alternative element should be used instead of img
. 要使用
background-image
属性,应使用替代元素代替img
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.