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

前端 未结 17 1741
不思量自难忘°
不思量自难忘° 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:39

    For future googlers, in 2016 there is a browser safe pure CSS way of hiding empty images using the attribute selector:

    img[src="Error.src"] {
        display: none;
    }
    

    Edit: I'm back - for future googlers, in 2019 there is a way to style the actual alt text and alt text image in the Shadow Dom, but it only works in developer tools. So you can't use it. Sorry. It would be so nice.

    #alttext-container {
        opacity: 0;
    }
    #alttext-image {
        opacity: 0;
    }
    #alttext {
        opacity: 0;
    }
    

提交回复
热议问题