赣州建站资讯网

为消费者提供更优质的体验

图片加载失败后CSS样式增加异常处理-图片加载异常占位图片处理


	<img src="zxx.png" alt="CSS新世界封面" onerror="this.classList.add('error');" width="100" height="100">
	<img src="https://www.zhangxinxu.com/study/202010/street.jpg" alt="CSS新世界封面" onerror="this.classList.add('error');" width="100" height="100">
<style>
img.error {
  display: inline-block;
  transform: scale(1);
  content: '';
  color: transparent;
}
img.error::before {
  content: '';
  position: absolute;
  left: 0; top: 0;
  width: 100%; height: 100%;
  background: #f5f5f5 url(https://www.zhangxinxu.com/study/202010/break.svg) no-repeat center / 50% 50%;
}
img.error::after {
  content: attr(alt);
  position: absolute;
  left: 0; bottom: 0;
  width: 100%;
  line-height: 2;
  background-color: rgba(0,0,0,.5);
  color: white;
  font-size: 12px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
</style>




- END -
声明:文字图片等素材除标明原创外均来源于网络,如有侵权,请及时告知我们,我们将在最短的时间内删除!
上一篇:呼吸灯效果
下一篇:css文字描边

相关推荐

微信公众平台:圆狐创意

关注圆狐创意微信公众平台浏览最新资讯

更多媒体及商务合作

QQ:295939675   或  至电:198-6662-0460