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

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

    Since 2005, Mozilla browsers such as Firefox have supported the non-standard :-moz-broken CSS pseudo-class that can accomplish exactly this request:

    td {
      min-width:64px; /* for display purposes so you can see the empty cell */
    }
    
    img[alt]:-moz-broken {
      display:none;
    }
    A broken image A bird

    img[alt]::before also works in Firefox 64 (though once upon a time it was img[alt]::after so this is not reliable). I can't get either of those to work in Chrome 71.

提交回复
热议问题