<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>图片文字遮罩</title>
<style type="text/css">
.box {
width: 200px;
height: 300px;
margin: 50px auto 0;
border: 1px solid #000;
position: relative;
overflow: hidden;
/* 溢出文字看不见*/
}
/* 后代选择器 将图片完整放在框中*/
.box img{
width:200px;
height: 300px;
}
.box .pic{
width: 200px;
height: 200px;
background-color:#000;
color:#fff;
position: absolute;
/*子元素开启绝对定位时 父元素也应该开启相对定位*/
left: 0;
top: 300px;
transition: all 500ms ease;
transition: all 1s cubic-bezier(0.28, -0.56, 0.755,1.445);
background-color: rgb(0,0,0,0.5);
}
.box:hover .pic{
top:150px;
/* 字体上升*/
}
.box .pic p {
margin: 20px;
line-height: 20px;
/* 拉高文字间距*/
}
</style>
</head>
<body>
<div class="box" >
<img src="1.jpg" alt="玫瑰花">
<div class="pic">
<p>
图片说明:这是一朵玫瑰花图片说明:这是一朵玫瑰花图片说明:这是一朵玫瑰花图片说明:这是一朵玫瑰花
</p>
</div>
</div>
</body>
</html>