效果:
源码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
* {
/* padding: 0;
margin: 0; */
text-decoration: none;
}
/* 外层容器设置宽高、开启相对定位,
作为动态盒子的定位点 */
.container {
width: 150px;
height: 140px;
position: relative;
border-radius: 5px;
}
/* 动态盒子开启绝对定位,并把bottom值设置为0,
调整盒子增长方向为由下往上 */
.inner1 {
font-size: 13px;
height: 60px;
transition: height 1s;
/* border: 1px solid red; */
position: absolute;
bottom: 0px;
color: gray;
background-color: rgb(226, 226, 217);
border-radius: 5px;
}
/* 开启定位,防止被inner1覆盖 */
.inner2 {
width: 100%;
text-align: center;
position: absolute;
bottom: 0;
/* border: 1px solid blue; */
color: gray;
}
/* 伪类,盒子变高 */
.container:hover .inner1 {
height: 100px;
/* background-color: lightblue; */
}
/* 网格布局,5列3行 */
.gridBox {
display: grid;
grid-template-columns: repeat(5, 1fr);
grid-template-rows: repeat(3, 1fr);
width: 850px;
height: 450px;
/* border: 1px solid red; */
}
/* 区域设置 */
.item1 {
grid-column: 1/2;
grid-row: 1/3;
/* background-color: red; */
}
.item {
margin: auto;
}
</style>
</head>
<body>
<div class="gridBox">
<div class="item item1">
<a href=""><img src="黑莲花.jpg" alt="" style="width: 150px;" /></a>
</div>
<div class="item">
<div class="container">
<a href="#">
<img
src="黑莲花.jpg"
alt=""
style="width: 150px; display: inline-block;"
/>
<div class="inner1">
<i>初级</i> <span>MYSQL面向对象极速入门</span>
<br />
<br />
</div>
<div class="inner2">
<span>20W+次播放</span>
</div>
</a>
</div>
</div>
<!-- 重复12次<div class="item">...</div> -->
</div>
</body>
</html>