背景

描述:当鼠标进入卡片的时候卡片高度变大,并且文字内容就会缓缓从上向下浮现,离开的时候,卡片高度变小,文字内容向上缓缓消失。

代码如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<!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>CSS响应式卡片悬停特效</title>
</head>
<body>
<div class="container">
<div class="card">
<div class="imgBx">
<img src="https://cdn.jsdelivr.net/gh/Daisy-1999/CDN/blog/card1.46bslpzeodk0.png" alt="">
</div>
<div class="content">
<h2>Card One</h2>
<p>是通过看清慢变量的方式,穿越到未来,然后回到现在,
用真金白银,甚至全部身家下注。是通过看清慢变量的方式,
穿越到未来,然后回到现在,
用真金白银,甚至全部身家下注。
</p>
</div>
</div>
<div class="card">
<div class="imgBx">
<img src="https://cdn.jsdelivr.net/gh/Daisy-1999/CDN/blog/card2.77w5wnfvhys0.png" alt="">
</div>
<div class="content">
<h2>Card Two</h2>
<p>是通过看清慢变量的方式,穿越到未来,然后回到现在,
用真金白银,甚至全部身家下注。是通过看清慢变量的方式,
穿越到未来,然后回到现在,
用真金白银,甚至全部身家下注。
</p>
</div>
</div>
<div class="card">
<div class="imgBx">
<img src="https://cdn.jsdelivr.net/gh/Daisy-1999/CDN/blog/card3.33g86ffovg00.png" alt="">
</div>
<div class="content">
<h2>Card Three</h2>
<p>是通过看清慢变量的方式,穿越到未来,然后回到现在,
用真金白银,甚至全部身家下注。是通过看清慢变量的方式,
穿越到未来,然后回到现在,
用真金白银,甚至全部身家下注。
</p>
</div>
</div>
</div>
</body>
<style>
*{
margin: 0;
padding: 0;
}
body{
display: flex;
align-items: center;
justify-content: center;
background: #16384c;
}
.container{
width: 1100px;
position: relative;
display: flex;
align-items: center;
justify-content: center;
flex-wrap: wrap;
padding: 30px;
}
.container .card{
max-width: 300px;
height: 215px;
position: relative;
background: #fff;
transition: 0.3s ease-in-out;
margin: 30px 10px;
padding: 20px 15px;
flex-direction: column;
box-shadow: 0 5px 20px rgba(0, 0, 0, 0.5);
}
.container .card:hover{
height: 420px;
}
.container .card .imgBx{
position: relative;
width: 260px;
height: 260px;
top: -60px;
left: 20px;
z-index: 1;
box-shadow: 0 5px 20px rgba(0, 0, 0, 0.2);
transition: 0.3s ease-in-out;
}
.container .card .imgBx img{
width: 100%;
border-radius: 4px;
height: 100%;

}
.container .card .content{
visibility: hidden;
position: relative;
margin-top: -140px;
padding: 10px 15px;
color: #111;
opacity: 0;
text-align: center;
transition: 0.3s ease-in-out;
}
.container .card:hover .content{
visibility: visible;
opacity: 1;
margin-top: -40px;
transition-delay: 0.3s;
}
</style>
</html>