简体   繁体   English

为什么在悬停时反转颜色的CSS不能在我的图片上使用?

[英]Why won't this CSS for inverting colours on hover work on my image?

 #menuleaf:hover, #menuleaf:focus { filter:invert(100%); } 
 <img id="menuleaf" src="https://image.flaticon.com/icons/svg/411/411289.svg" height=13px" /> 

What is the problem exactly? 到底是什么问题? All the tutorials I can find make it seem like it should be as easy as this? 我能找到的所有教程看起来都应该像这样简单吗?

Typo: 错字:

You have an invalid white-space character between :focus and { : 您在:focus{之间有无效的空格字符:

 const str= `#imgname:hover, #imgname:focus {`; console.log(str.split('focus')[1].charCodeAt(0)); // space is 32 

Fixing this typo will make your rule work: 解决此错字将使您的规则生效:

 #imgname:hover, #imgname:focus { filter:invert(100%); } 
 <img id="imgname" src="https://upload.wikimedia.org/wikipedia/commons/f/fd/Ghostscript_Tiger.svg" height="13px" /> 

And also note that while it's not the issue here, your height attribute misses an opening " . 还要注意,虽然这不是问题,但您的height属性缺少一个开头"

Your image source doesn't look like it would load correctly. 您的图片源看起来好像无法正确加载。 Give the correct location of the image inside src . src内给出图像的正确位置。

then invert the image 然后反转图像

#imgname:hover,#imgname:focus {
  -webkit-filter: invert(100%);
          filter: invert(100%);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM