html+css实现响应式卡片悬停效果
2021-03-15 04:01
1436 查看
话不多,看效果先:
卡片悬停,响应式卡片,简约效果。
实现:
1. 定义标签,.kapian为最底层盒子,然后两个子盒子一个放图片,一个放文本:
<div class="kapian"> <div class="tu"> <img src="3.2.png"> </div> <div class="wenben"> <h2>The aurora borealis</h2> <p style="padding-bottom: 20px;">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>
2.先定义底层盒子的css基本样式,长宽等,就不详细说明了:
.kapian{ 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 0.3s; } .kapian:hover{ box-shadow: 2px 3px 10px rgb(36, 35, 35); }
:hover鼠标经过后盒子阴影变化。
transition: all 0.3s;过渡效果,阴影在0.3s内慢慢变化
3. 图片的基本样式,采用绝对定位:
.tu{ position: absolute; top: 0; left: 0; width: 100%; height: 300px; overflow: hidden; } .tu img{ width: 100%; height: 100%; transition: all 0.5s; } .kapian:hover .tu img{ transform: scale(1.2); filter: blur(1px); }
:hover鼠标经过后图片变大,而且变模糊;
transform: scale(1.2);图片变大为1.2倍;
filter: blur(1px);图片变模糊;
4 .定义装文本这个盒子的基本样式,采用绝对定位:
.wenben{ position: absolute; bottom: -200px; width: 100%; height: 300px; background-color: rgb(247, 242, 242); transition: 0.5s; } .kapian:hover .wenben{ bottom: 0px; }
:hover鼠标经过后文本框绝对定位的bottom发生改变,使得呈现文本框向上展开的效果;
5 .文本框里字符的样式:
.wenben h2{ color: rgb(21, 74, 172); line-height: 60px; text-align: center; } .wenben p{ padding: 0 30px; font-family: 'fangsong'; font-size: 16px; font-weight: bold; line-height: 20px; text-align: center; }
完整代码:
<!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> *{ margin: 0; padding: 0; box-sizing: border-box; } body{ height: 100vh; display: flex; justify-content: center; align-items: center; background-image: radial-gradient(rgb(241, 238, 238),black); }.kapian{ 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 0.3s; } .kapian:hover{ box-shadow: 2px 3px 10px rgb(36, 35, 35); }.tu{ position: absolute; top: 0; left: 0; width: 100%; height: 300px; overflow: hidden; } .tu img{ width: 100%; height: 100%; transition: all 0.5s; } .kapian:hover .tu img{ transform: scale(1.2); filter: blur(1px); } .wenben{ position: absolute; bottom: -200px; width: 100%; height: 300px; background-color: rgb(247, 242, 242); transition: 0.5s; } .kapian:hover .wenben{ bottom: 0px; }.wenben h2{ color: rgb(21, 74, 172); line-height: 60px; text-align: center; } .wenben p{ padding: 0 30px; font-family: 'fangsong'; font-size: 16px; font-weight: bold; line-height: 20px; text-align: center; } </style> </head> <body><div class="kapian"> <div class="tu"> <img src="3.2.png"> </div> <div class="wenben"> <h2>The aurora borealis</h2> <p style="padding-bottom: 20px;">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> </body> </html>
总结:
希望在路上~
到此这篇关于 html+css实现响应式卡片悬停效果的文章就介绍到这了,更多相关html css卡片悬停内容请搜索脚本之家以前的文章或继续浏览下面的相关文章,希望大家以后多多支持脚本之家!
相关文章推荐
- html+css+js实现导航栏滚动渐变效果
- 使用HTML和JavaScript播放本地的媒体(视频音频)文件的方法
- HTML 拖拉功能的实现代码
- html列表框、文本域、文件域的示例代码
- HTML页面缩小后显示滚动条的示例代码
- html table呈现个人简历以及单元格宽度失效的问题解决
- 使用HTML和CSS实现的标签云效果(附demo)
- CSS复合选择器的具体使用方法
- CSS让子元素div的高度填满父容器的剩余空间的方法
- 详解CSS多种三列自适应布局实现
- CSS弹性布局FLEX,媒体查询及移动端点击事件的实现
- 纯 CSS 实现拖拽效果的代码
- 纯CSS实现页面中的列表收拉效果
- css圆形镂空(优惠券背景图)的实现
- css animation配合SVG制作能量流动效果
- 如何通过 CSS 写出火焰效果
- CSS实现图像映射的方法
- CSS实现fullpage.js全屏滚动效果的示例代码
- html+css实现充电水滴融合特效代码