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

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

    You can follow this path as a css solution

    img {
            width:200px;
            height:200px;
            position:relative
       }
    img:after {
            content: "";
            position: absolute;
            top: 0;
            left: 0;
            width: inherit;
            height: inherit;
            background: #ebebeb url('http://via.placeholder.com/300?text=PlaceHolder') no-repeat center;
            color: transparent;
        }

提交回复
热议问题