需求:

图片加载失败后给图片标签加上一个类名,给该类添加伪元素引入我们自己需要的加载失败图片覆盖在裂掉的图片上,并把alt内容加载显示在其中

HTML

<img src="imgX.png" alt=alt内容" onerror="this.classList.add('error');">

CSS

img.error {  display: inline-block;  transform: scale(1);  content: '';  color: transparent; } img.error::before {  content: '';  position: absolute;  left: 0; top: 0;  width: ; height: ;  background: #f5f5f5 url(img.png) no-repeat center / 50% 50%; } img.error::after {  content: attr(alt);  position: absolute;  left: 0; bottom: 0;  width: ;  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; }


我们凭借多年的网站建设经验,坚持以“帮助中小企业实现网络营销化”为宗旨,累计为4000多家客户提供品质建站服务,得到了客户的一致好评。如果您有网站建设、网站改版、域名注册、主机空间、手机网站建设、网站备案等方面的需求...
请立即点击咨询我们或拨打咨询热线: 189-0971-7171,我们会详细为你一一解答你心中的疑难。项目经理在线

我们已经准备好了,你呢?

2020我们与您携手共赢,为您的企业形象保驾护航!

在线客服
联系方式

热线电话

189-0971-7171

上班时间

周一到周五

公司电话

400-0971-365

二维码
线
在线留言