简体   繁体   中英

How to hide images based on src 301 redirect URL attribute?

I can hide all images with matching src attribute using a CSS3 attribute selector. For example:

img[src*="photo_unavailable"] {
display: none;
}

will hide images with src containing "photo_unavailable".

However, what about an image like this:

https://farm7.static.flickr.com/6180/6172064687_834c859b5c_b.jpg

which redirects to:

https://s.yimg.com/pw/images/en-us/photo_unavailable_l.png

Is there a way to hide the image based on a string "photo_unavailable" found in the redirected src?

No, that is not possible. Because the src attribute correspond to the "broken" image link, not the "photo_unavailable" link.

It can be tricki - just put your image inside a element

HTML

 <a href="https://s.yimg.com/pw/images/en-us/photo_unavailable_l.png" >
      <img src="https://farm7.static.flickr.com/6180/6172064687_834c859b5c_b.jpg"/>
    </a>

CSS

a[href*="photo_unavailable"] > img  , img[src*="photo_unavailable"]  {
display: none;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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