方法有很多种,下面我介绍一种纯CSS的实现的方式:
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="utf-8" />
<title></title>
<style>
html,
body {
margin: 0;
padding: 0;
}
.main {
width: 460px;/*每个box的宽度为150px,间隔为5*2*/
margin: 0 auto;
}
.demo {
float: left;
display: inline-block;
}
.box {
height: 150px;
width: 150px;
background: #3695d5;
position: relative;
overflow: hidden;
}
.inbox {
height: 50px;
line-height: 50px;
text-align: center;
color: #FFF;
width: 100%;
position: absolute;
bottom: -50px;
background: rgba(0, 0, 0, 0.3);
transition: 1s;/*过渡效果*/
}
.box:hover>.inbox {
bottom: 0;
}
</style>
</head>
<body>
<div class="main">
<div class="demo">
<div class="box">
图片
<div class="inbox">
文字
</div>
</div>
</div>
<div class="demo" style="margin: 0 5px 0 5px;">
<div class="box">
图片
<div class="inbox">
文字
</div>
</div>
</div>
<div class="demo">
<div class="box">
图片
<div class="inbox">
文字
</div>
</div>
</div>
</div>
</body>
</script>
</html>