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

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

    If you will add alt with text alt="abc" it will show the show corrupt thumbnail, and alt message abc

    abc
    

    If you will not add alt it will show the show corrupt thumbnail

    
    

    If you want to hide the broken one just add alt="" it will not show corrupt thumbnail and any alt message(without using js)

    
    

    If you want to hide the broken one just add alt="" & onerror="this.style.display='none'" it will not show corrupt thumbnail and any alt message(with js)

    abc
    

    4th one is a little dangerous(not exactly) , if you want to add any image in onerror event, it will not display even if Image exist as style.display is like adding. So, use it when you don't require any alternative image to display.

    display: 'none'; // in css
    

    If we give it in CSS, then the item will not display(like image, iframe, div like that).

    If you want to display image & you want to display totally blank space if error, then you can use, but also be careful this will not take any space. So, you need to keep it in a div may be

    Link https://jsfiddle.net/02d9yshw/

提交回复
热议问题