<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="fonts/iconfont.css">
<title>华为案例</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.box {
position: relative;
width: 450px;
height: 310px;
background-color: aqua;
overflow: hidden;
}
.box img {
width: 450px;
height: 310px;
transition: all 1s;
}
.box:hover img {
transform: scale(1.1);
}
.box::after {
position: absolute;
top: 0;
left: 0;
opacity: 0;
content: "";
width: 100%;
height: 100%;
background:linear-gradient(rgba(0,0,0,0),rgba(0,0,0,0.5));
transition: all 1s;
}
.box:hover::after {
opacity: 1;
}
.hidden {
position: absolute;
left: 20px;
bottom: -46px;
z-index: 2;
/*width: 100%;*/
/*height: 100%;*/
/*盒子宽高由内容撑开
盒子内部 默认 从左上开始排版
不是bottom 0 失效
是对盒子的性质 理解有偏差*/
opacity: 1;
transition: all 1s;
}
.hidden p {
color: #fff;
font-size: 18px;
margin: 5px;
}
.hidden h3 {
color: #fff;
font-size: 24px;
margin: 5px;
}
.hidden a {
display: block;
color: #fff;
text-decoration: none;
font-size: 18px;
margin-bottom: 20px;
}
.hidden .iconfont {
color: #fff;
font-size: 18px;
margin: 5px;
}
.box:hover .hidden {
bottom: 0;
}
</style>
</head>
<body>
<div class="box">
<img src="images/1.jpg" alt="">
<div class="hidden">
<p>白皮书</p>
<h3>拥抱5.5G时代迈向智能世界</h3>
<p>《迈向智能世界》系列白皮书发布</p>
<a href="#">了解更多 <i class="iconfont icon-youjiantou"></i></a>
</div>
</div>
</body>
</html>
本html涉及到的知识点, img上不能直接加绝对定位,因此需要用一个盒子将其包起来,再设置外盒子为相对定位, 图片放大属性的优先级较高,因此无论是鼠标移动上去后产生的阴影,还是文字,都应该在逻辑上位于图片之后,这样才能实现预期的效果.