<template>
<div style="padding: 20px">
<img alt="我是一张苹果的照片">
</div>
</template>
<style scoped>
img {
display: inline-block;
width: 200px;
height: 100px;
/* 隐藏Firefox alt文字 */
color: transparent;
position: relative;
overflow: hidden;
}
img:not([src]) {
/* 隐藏Chrome alt文字以及银色边框 */
visibility: hidden;
}
img::before {
/* 淡蓝色占位背景 */
content: "";
position: absolute;
left: 0;
width: 100%;
height: 100%;
background-color: #f0f3f9;
visibility: visible;
}
img::after {
/* 黑色alt信息条 */
content: attr(alt);
position: absolute;
left: 0;
bottom: 0;
width: 100%;
line-height: 30px;
background-color: rgba(0, 0, 0, .5);
color: white;
font-size: 14px;
text-align: center;
transform: translateY(100%);
/* 来点过渡动画效果 */
transition: transform .2s;
visibility: visible;
}
img:hover::after {
transform: translateY(0);
}
</style>