<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>遮罩文字</title>
<style>
body,
ul,p{
padding: 0;
margin: 0
}
li {
list-style: none;
}
a {
text-decoration: none;
color: #000;
}
.ul {
display: flex;
}
li{
width:40%;
margin:0.2rem;
position: relative;
}
li img {
width: 100%;
}
li p{
width:100%;
height:35px;
line-height: 35px;
position: absolute;
left:0;
bottom: 0.2rem;
background-color: rgba(0, 0, 0, 0.5);
font-size: 18px;
text-align: center
}
</style>
</head>
<body>
<ul class="ul">
<li>
<a href="">
<img src="1.JPG" alt="">
<p>这是显示的文字</p>
</a>
</li>
<li>
<a href="">
<img src="1.JPG" alt="">
<p class="p">这是显示的文字</p>
</a>
</li>
<li>
<a href="">
<img src="1.JPG" alt="">
<p class="p">这是显示的文字</p>
</a>
</li>
</ul>
</body>
</html>
注意:父元素为相对定位(relative),子元素为绝对定位(absolute)
效果图为: