How to hide image broken Icon using only CSS/HTML?

前端 未结 17 1751
不思量自难忘°
不思量自难忘° 2020-11-27 09:14

How can I hide the broken image icon? Example: \"Example\"

I have an image with error src:

17条回答
  •  感情败类
    2020-11-27 09:52

    If you need to still have the image container visible due to it being filled in later on and don't want to bother with showing and hiding it you can stick a 1x1 transparent image inside of the src:

    I used this for this exact purpose. I had an image container that was going to have an image loaded into it via Ajax. Because the image was large and took a bit to load, it required setting a background-image in CSS of a Gif loading bar.

    However, because the src of the was empty, the broken image icon still appeared in browsers that use it.

    Setting the transparent 1x1 Gif fixes this problem simply and effectively with no code additions through CSS or JavaScript.

提交回复
热议问题