CSS 隐藏所有具有匹配 SRC 属性的图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6763899/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
CSS hide all images with matching SRC attribute
提问by Devil's Advocate
Is it possible to create a CSS rule that would apply a style to any IMG tag with a SRC that contained a specific string, say "hideme"? For instance, if I had the following 3 images on a page it would hide the second one?
是否可以创建一个 CSS 规则,将样式应用于任何带有包含特定字符串的 SRC 的 IMG 标签,比如“hideme”?例如,如果我在一个页面上有以下 3 张图片,它会隐藏第二张吗?
<img src="images/test1.png">
<img src="images/hideme.gif">
<img src="images/test3.jpg">
回答by BoltClock
Use this CSS3 attribute selector:
使用这个 CSS3属性选择器:
img[src*="hideme"] {
display: none;
}
I'd prefer to use a hideme
class instead, but if you must hide an image based on its src
attribute, the above is fine.
我更喜欢使用hideme
类,但如果您必须根据其src
属性隐藏图像,则上述方法很好。