HTML+CSS+JS:轮播组件

效果演示

一个具有动画效果的卡片元素和一个注册表单,背景为渐变色,整体布局简洁美观。

Code

html 复制代码
<div class="card" style="--d:-1;">
    <div class="content">
        <div class="img">
            <img src="./img/果果k_01.jpg" alt="">
        </div>
        <div class="detail">
            <span>若冰儿(RuoBing)</span>
            <p>寻找真爱的微笑使者。</p>
        </div>
    </div>
    <a href="#">关注</a>
</div>
<div class="card" style="--d:0;">
    <div class="content">
        <div class="img">
            <img src="./img/果果k_02.jpg" alt="">
        </div>
        <div class="detail">
            <span>李晓雪(Lixiaoxue)</span>
            <p>用心灵构建美好的婚姻。</p>
        </div>
    </div>
    <a href="#">关注</a>
</div>
<div class="card" style="--d:1;">
    <div class="content">
        <div class="img">
            <img src="./img/瞳瞳_01.jpg" alt="">
        </div>
        <div class="detail">
            <span>何璐(Helu)</span>
            <p>相信缘分,等待幸福的到来。</p>
        </div>
    </div>
    <a href="#">关注</a>
</div>
    <div class="card" style="--d:2;">
        <div class="content">
            <div class="img">
                <img src="./img/瞳瞳_02.jpg" alt="">
            </div>
            <div class="detail">
                <span>谷亚楠(Guyanan)</span>
                <p>热情洋溢,寻找属于我的爱情。</p>
            </div>
        </div>
        <a href="#">关注</a>
    </div>
    <div class="card" style="--d:3;">
        <div class="content">
            <div class="img">
                <img src="./img/瞳瞳_03.jpg" alt="">
            </div>
            <div class="detail">
                <span>何瑞(Herui)</span>
                <p>勇敢追求幸福,不断向前。</p>
            </div>
        </div>
        <a href="#">关注</a>
    </div>
</div>

<div class="register">
    <p>60秒完成注册,幸福一辈子!</p>
    <div class="btn">免费注册</div>
</div>
css 复制代码
* {
    margin: 0; /* 设置所有元素的外边距为0 */
    padding: 0; /* 设置所有元素的内边距为0 */
}

body {
    height: 100vh; /* 设置body元素的高度为视口高度 */
    display: flex; /* 使用flex布局 */
    justify-content: center; /* 水平居中 */
    align-items: center; /* 垂直居中 */
    background: linear-gradient(200deg, #fda09b, #918ef9); /* 设置背景为200度的线性渐变色 */
}

.container {
    display: flex; /* 使用flex布局 */
    justify-content: center; /* 水平居中 */
    align-items: center; /* 垂直居中 */
    position: relative; /* 相对定位 */
    width: 500px; /* 宽度为500px */
    height: 300px; /* 高度为300px */
}

.card {
    width: 430px; /* 宽度为430px */
    height: 100px; /* 高度为100px */
    background-color: #fff; /* 背景颜色为白色 */
    border-radius: 100px 20px 20px 100px; /* 圆角设置 */
    position: absolute; /* 绝对定位 */
    padding: 0 20px; /* 内边距 */
    display: flex; /* 使用flex布局 */
    justify-content: space-between; /* 项目之间均匀分布 */
    align-items: center; /* 垂直居中 */
    opacity: 0; /* 初始透明度为0 */
    animation: animate 10s linear infinite; /* 应用名为animate的动画,持续10秒,线性变化,无限循环 */
    animation-delay: calc(2s * var(--d)); /* 动画延迟时间根据变量--d计算 */
}

/* 鼠标移入,动画暂停 */
.container:hover .card {
    animation-play-state: paused; /* 鼠标悬停时,卡片动画暂停 */
}

.card .img {
    width: 90px; /* 宽度为90px */
    height: 90px; /* 高度为90px */
    position: absolute; /* 绝对定位 */
    left: 0; /* 左边距为0 */
    top: 0; /* 上边距为0 */
    background-color: #fff; /* 背景颜色为白色 */
    padding: 5px; /* 内边距 */
    border-radius: 50%; /* 圆角设置 */
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.2); /* 设置阴影 */
}

.card .img img {
    width: 100%; /* 图片宽度100% */
    height: 100%; /* 图片高度100% */
    object-fit: cover; /* 图片填充父容器,保持比例 */
    border-radius: 50%; /* 圆角设置 */
}

.card .content {
    display: flex; /* 使用flex布局 */
    align-items: center; /* 垂直居中 */
}

.card .detail {
    margin-left: 100px; /* 左边距为100px */
}

.card .detail span {
    display: block; /* 设置为块级元素 */
    font-size: 18px; /* 字体大小为18px */
    font-weight: 600; /* 字体加粗 */
    margin-bottom: 8px; /* 底部外边距为8px */
}

.card a {
    font-size: 14px; /* 字体大小为14px */
    text-decoration: none; /* 文本装饰为无 */
    background: linear-gradient(to bottom, #fbc5ed, #a6c1ee); /* 背景为垂直渐变色 */
    padding: 7px 18px; /* 内边距 */
    color: #fff; /* 文本颜色为白色 */
    border-radius: 25px; /* 圆角设置 */
}

/* 定义动画 */
@keyframes animate {
    0% {
        opacity: 0;
        transform: translateY(100%) scale(0.5);
    }
    /* 省略部分关键帧动画定义 */
}

.register {
    width: 400px; /* 宽度为400px */
    height: 200px; /* 高度为200px */
    background-color: rgba(0, 0, 0, 0.65); /* 背景颜色为带透明度的黑色 */
    box-shadow: 0px 2px 11px 0px rgba(0, 0, 0, 0.5); /* 设置阴影 */
    padding: 0 30px; /* 内边距 */
    border-radius: 5px; /* 圆角设置 */
    margin-left: 30px; /* 左边距为30px */
}

.register p {
    color: #fff; /* 文本颜色为白色 */
    font-size: 24px; /* 字体大小为24px */
    line-height: 86px; /* 行高为86px */
    text-align: center; /* 文本居中对齐 */
    height: 80px; /* 高度为80px */
    border-bottom: 1px solid #eee; /* 底部边框为1px实线,颜色为浅灰色 */
}

.register .btn {
    height: 60px; /* 高度为60px */
    line-height: 60px; /* 行高为60px */
    font-size: 24px; /* 字体大小为24px */
    border-radius: 4px; /* 圆角设置 */
    padding: 0 20px; /* 内边距 */
    margin-top: 20px; /* 上边距为20px */
    text-align: center; /* 文本居中对齐 */
    color: #fff; /* 文本颜色为白色 */
    background: linear-gradient(-135deg, #856df1, #a468ef); /* 背景为从左上到右下的渐变色 */
    cursor: pointer; /* 鼠标指针样式为手型 */
}
相关推荐
2501_94452554几秒前
Flutter for OpenHarmony 个人理财管理App实战 - 支出分析页面
android·开发语言·前端·javascript·flutter
jin12332239 分钟前
React Native鸿蒙跨平台完成剧本杀组队详情页面,可以复用桌游、团建、赛事等各类组队详情页开发
javascript·react native·react.js·ecmascript·harmonyos
李白你好41 分钟前
Burp Suite插件用于自动检测Web应用程序中的未授权访问漏洞
前端
经年未远2 小时前
vue3中实现耳机和扬声器切换方案
javascript·学习·vue
刘一说2 小时前
Vue 组件不必要的重新渲染问题解析:为什么子组件总在“无故”刷新?
前端·javascript·vue.js
可触的未来,发芽的智生2 小时前
狂想:为AGI代称造字ta,《第三类智慧存在,神的赐名》
javascript·人工智能·python·神经网络·程序人生
徐同保3 小时前
React useRef 完全指南:在异步回调中访问最新的 props/state引言
前端·javascript·react.js
fanruitian3 小时前
uniapp 创建项目
javascript·vue.js·uni-app
刘一说3 小时前
Vue 导航守卫未生效问题解析:为什么路由守卫不执行或逻辑失效?
前端·javascript·vue.js
一周七喜h4 小时前
在Vue3和TypeScripts中使用pinia
前端·javascript·vue.js