CSS hide all images with matching SRC attribute

2019-03-08 22:05发布

问题:

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?

<img src="images/test1.png">
<img src="images/hideme.gif">
<img src="images/test3.jpg">

回答1:

Use this CSS3 attribute selector:

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.