?效果如下:
首先要做的就是先考虑清楚布局效果,这里采用上下布局,上面是图片,下面则是图片的一些说明性文本
考虑到复用性这里主要利用ul li 进行布局
大致的布局如下:
<ul>
<li>
<div class="container">
<div class="img">
<img src="./images/chun.jpg" alt="">
</div>
<div class="info">
<h2>The aurora borealis</h2>
<p>natural</p>
<p>Aurora Borealis is a colorful luminous phenomenon that appears over the high magnetic latitude region of the planet's North Pole.I love the aurora borealis. It's so beautiful.</p>
</div>
</div>
</li>
</ul>
接下来就是设置底层盒子的样式,即.container的基本样式,这里考虑到当鼠标移动到盒子上时会给它添加一个hover效果也就是设置盒子阴影效果
大致代码如下:
.container {
position: relative;
width: 300px;
height: 400px;
border-radius: 3px;
background-color: #fff;
box-shadow: 2px 3px 3px rgb(139,138,138);
overflow: hidden;
cursor: pointer;
transition: all .3s;
}
.container:hover {
box-shadow: 2px 3px 10px rgb(36,35,35);
}
其次就是设置盒子里顶部的图片区域以及图片的基础样式
代码大致如下:
.img {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 300px;
overflow: hidden;
}
.img img {
width: 100%;
height: 100%;
transition: all .5s;
}
紧接着需要实现的就是当鼠标移动到盒子上时,盒子里面的图片放大1.2倍并设置其高斯模糊效果
大致代码如下:
.container:hover .img img {
transform: scale(1.2);
/* 设置图片的高斯模糊效果 */
filter: blur(1px);
}
最后就是设置盒子底部的文本区域的基本样式以及当鼠标移动到盒子上时底部文字的一个效果
大致代码如下:
.info {
position: absolute;
bottom: -200px;
width: 100%;
height: 300px;
background-color: rgb(247,242,242);
transition: all .5s;
}
.container:hover .info {
bottom: 0px;
}
.info h2 {
color: rgb(21,74,172);
line-height: 60px;
text-align: center;
}
.info p {
padding: 0 30px;
font-family: 'fangsong';
font-size: 16px;
font-weight: 700;
line-height: 20px;
text-align: center;
}
所有代码:
<!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">
<title>响应式卡片悬停效果</title>
<style>
* {
margin: 0;
padding: 0;
}
ul,li {
list-style: none;
}
ul {
width: 1200px;
margin: 0 auto;
}
ul li {
float: left;
/* margin-right: 10px; */
margin: 0 150px 10px 0;
}
ul li:nth-of-type(3) {
margin-right: 0px;
}
.info p:nth-of-type(1) {
margin-bottom: 20px;
}
.container {
position: relative;
width: 300px;
height: 400px;
border-radius: 3px;
background-color: #fff;
box-shadow: 2px 3px 3px rgb(139,138,138);
overflow: hidden;
cursor: pointer;
transition: all .3s;
}
.container:hover {
box-shadow: 2px 3px 10px rgb(36,35,35);
}
.img {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 300px;
overflow: hidden;
}
.img img {
width: 100%;
height: 100%;
transition: all .5s;
}
.container:hover .img img {
transform: scale(1.2);
/* 设置图片的高斯模糊效果 */
filter: blur(1px);
}
.info {
position: absolute;
bottom: -200px;
width: 100%;
height: 300px;
background-color: rgb(247,242,242);
transition: all .5s;
}
.container:hover .info {
bottom: 0px;
}
.info h2 {
color: rgb(21,74,172);
line-height: 60px;
text-align: center;
}
.info p {
padding: 0 30px;
font-family: 'fangsong';
font-size: 16px;
font-weight: 700;
line-height: 20px;
text-align: center;
}
</style>
</head>
<body>
<!-- <div class="container"> -->
<ul>
<li>
<div class="container">
<div class="img">
<img src="./images/chun.jpg" alt="">
</div>
<div class="info">
<h2>The aurora borealis</h2>
<p>natural</p>
<p>Aurora Borealis is a colorful luminous phenomenon that appears over the high magnetic latitude region of the planet's North Pole.I love the aurora borealis. It's so beautiful.</p>
</div>
</div>
</li>
<li>
<div class="container">
<div class="img">
<img src="./images/chun.jpg" alt="">
</div>
<div class="info">
<h2>The aurora borealis</h2>
<p>natural</p>
<p>Aurora Borealis is a colorful luminous phenomenon that appears over the high magnetic latitude region of the planet's North Pole.I love the aurora borealis. It's so beautiful.</p>
</div>
</div>
</li>
<li>
<div class="container">
<div class="img">
<img src="./images/chun.jpg" alt="">
</div>
<div class="info">
<h2>The aurora borealis</h2>
<p>natural</p>
<p>Aurora Borealis is a colorful luminous phenomenon that appears over the high magnetic latitude region of the planet's North Pole.I love the aurora borealis. It's so beautiful.</p>
</div>
</div>
</li>
<li>
<div class="container">
<div class="img">
<img src="./images/chun.jpg" alt="">
</div>
<div class="info">
<h2>The aurora borealis</h2>
<p>natural</p>
<p>Aurora Borealis is a colorful luminous phenomenon that appears over the high magnetic latitude region of the planet's North Pole.I love the aurora borealis. It's so beautiful.</p>
</div>
</div>
</li>
</ul>
<!-- </div> -->
</body>
</html>
|