HTML+CSS实现玻璃形态卡片悬停效果!!附源码!!

[复制链接]
七夏(UID:1) 发表于 2024-12-22 17:05:32 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×

图片

完整源码

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
    <title>上浮文字</title>
    <style>
        /* 引入网络字体:Poppins */
@import url("http://fonts.googleapis.com/css?family=Poppins:200,300,400,500,600,700,800,900&display=swap");
*{
    /* 初始化 */
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    /* 设置字体 */
    font-family: "Poppins";
}
body{
    /* 100%窗口高度 */
    min-height: 100vh;
    /* 弹性布局 水平+垂直居中 */
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #161626;
}
/* 给背景增加两个渐变圆 */
body::before{
    content: "";
    /* 绝对定位 */
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    /* 渐变背景 */
    background: linear-gradient(#2193b0,#6dd5ed);
    /* 将元素剪切微一个圆形【30%表示圆的直径】【right 70%表示圆心位置】 */
    clip-path: circle(30% at right 70%);
}
body::after{
    content: "";
    /* 绝对定位 */
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    /* 渐变背景 */
    background: linear-gradient(#ee9ca7,#ffdde1);
    /* 将元素剪切微一个圆形【30%表示圆的直径】【right 70%表示圆心位置】 */
    clip-path: circle(20% at 10% 10%);
}
.container{
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    z-index: 1;
}
.container .card{
    /* 相对定位 */
    position: relative;
    width: 280px;
    height: 400px;
    background-color: rgba(255,255,255,0.1);
    margin: 30px;
    border-radius: 15px;
    /* 阴影 */
    box-shadow: 20px 20px 50px rgba(0,0,0,0.5);
    /* 溢出隐藏 */
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    border-top: 1px solid rgba(255,255,255,0.5);
    border-left: 1px solid rgba(255,255,255,0.5);
    /* 背景模糊 */
    backdrop-filter: blur(5px);
}
.container .card .content{
    padding: 20px;
    text-align: center;
    /* 默认下移+隐藏 */
    transform: translateY(100px);
    opacity: 0;
    transition: 0.5s;
}
.container .card:hover .content{
    /* 鼠标移入,上移+显示 */
    transform: translateY(0);
    opacity: 1;
}
.container .card .content h2{
    position: absolute;
    top: -80px;
    right: 25px;
    font-size: 128px;
    color: rgba(255,255,255,0.05);
}
.container .card .content h3{
    font-size: 28px;
    color: #fff;
}
.container .card .content p{
    font-size: 16px;
    color: #fff;
    font-weight: 300;
    margin: 10px 0 15px 0;
}
.container .card .content a{
    position: relative;
    display: inline-block;
    padding: 8px 20px;
    margin-top: 15px;
    background-color: #fff;
    color: #000;
    text-decoration: none;
    border-radius: 20px;
    font-weight: 500;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}
/* 这里要让玻璃效果更加逼真,需要用到一个JS库:vanilla-tilt.js */
/* 我事先下载好了,需要这个JS库的可以找我拿 */
/* 看操作~ */
    </style>
</head>
<body>
    <div class="container">
        <div class="card">
            <div class="content">
                <h2>01</h2>
                <h3>Card One</h3>
                <p>Realistic glass card hover effect, realistic glass card hover effect, realistic glass card hover effect.</p>
                <a href="#">Read More</a>
            </div>
        </div>
        <div class="card">
            <div class="content">
                <h2>02</h2>
                <h3>Card Two</h3>
                <p>Realistic glass card hover effect, realistic glass card hover effect, realistic glass card hover effect.</p>
                <a href="#">Read More</a>
            </div>
        </div>
        <div class="card">
            <div class="content">
                <h2>03</h2>
                <h3>Card Three</h3>
                <p>Realistic glass card hover effect, realistic glass card hover effect, realistic glass card hover effect, realistic glass card hover effect.</p>
                <a href="#">Read More</a>
            </div>
        </div>
    </div>
    <script src="../js/vanilla-tilt.js"></script>
    <script>
        // vanilla-tilt.js是一个平滑的3D倾斜JS库,具体参数配置度娘可查到
        VanillaTilt.init(document.querySelectorAll(".card"),{
            max: 15,  //最大倾斜度数
            speed: 400,  //倾斜转换的速度
            glare: true,  //是否开启眩光效果
            "max-glare": 1  //最大眩光的不透明度
        })
    </script>
</body>
</html>
小时候,看腻了农村的牛和马,长大后,来到了城里,才知道原来到处都是牛马!
全部回复2 显示全部楼层
China(UID:49) 发表于 2024-12-24 17:02:56 | 显示全部楼层
我现在要啥页面都是用AI写了,我连软件都是AI去写,懒得动脑子了
3BBS-拥有用户名和UID最多的男人
七夏(UID:1) 发表于 2024-12-24 17:31:41 | 显示全部楼层
China 发表于 2024-12-24 17:02
我现在要啥页面都是用AI写了,我连软件都是AI去写,懒得动脑子了

AI才是第一生产力🤣
小时候,看腻了农村的牛和马,长大后,来到了城里,才知道原来到处都是牛马!

快速回帖

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1楼
2楼
3楼

关于楼主

管理员
  • 主题

    924
  • 回答

    359
  • 积分

    2515
虚位以待,此位置招租

商务推广

    此位置招租 黑粉猫影院-免费看电影 此位置招租 此位置招租 此位置招租 此位置招租 此位置招租 此位置招租 此位置招租 此位置招租