HTML&CSS:产品卡片动画效果

这个 HTML 文件创建了一个视觉效果精美的产品卡片的动画效果。


大家复制代码时,可能会因格式转换出现错乱,导致样式失效。建议先少量复制代码进行测试,若未能解决问题,私信回复源码两字,我会发送完整的压缩包给你。

演示效果

HTML&CSS

html 复制代码
<!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>
        body {
            background: linear-gradient(135deg,
                    rgba(226, 226, 226, 1) 0%,
                    rgba(219, 219, 219, 1) 50%,
                    rgba(209, 209, 209, 1) 50%,
                    rgba(209, 209, 209, 1) 50%,
                    rgba(254, 254, 254, 1) 100%) center/cover no-repeat;
            min-height: 100vh;
        }

        .card {
            width: 360px;
            background: #fff;
            border-radius: 15px;
            box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
            transition: 0.3s;
            font-family: "Segoe UI", sans-serif;
            margin: 20px auto;
            overflow: hidden;
            position: relative;
            cursor: pointer;
        }

        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
        }

        .badge {
            position: absolute;
            top: 10px;
            right: 10px;
            background: linear-gradient(to right,
                    rgba(169, 3, 41, 1) 0%,
                    rgba(196, 72, 72, 1) 44%,
                    rgba(170, 34, 56, 1) 100%);
            color: #fff;
            padding: 5px 10px;
            font-size: 11px;
            font-weight: 600;
            letter-spacing: 1px;
            text-transform: uppercase;
            border-radius: 10px;
            box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
            z-index: 10;
        }

        .tilt {
            overflow: hidden;
        }

        .img {
            height: 200px;
            overflow: hidden;
        }

        .img img {
            width: 100%;
            height: 100%;
            object-fit: cover;
            transition: transform 0.5s;
        }

        .card:hover .img img {
            transform: scale(1.05);
        }

        .info {
            padding: 20px;
        }

        .cat {
            font-size: 11px;
            font-weight: 600;
            letter-spacing: 1px;
            text-transform: uppercase;
            color: #71717a;
            margin-bottom: 5px;
        }

        .title {
            font-size: 18px;
            font-weight: 700;
            color: #18181b;
            margin: 0 0 10px;
            letter-spacing: -0.5px;
        }

        .desc {
            font-size: 13px;
            color: #52525b;
            line-height: 1.4;
            margin-bottom: 12px;
        }

        .feats {
            display: flex;
            gap: 6px;
            margin-bottom: 15px;
        }

        .feat {
            font-size: 10px;
            background: #f4f4f5;
            color: #71717a;
            padding: 3px 8px;
            border-radius: 10px;
            font-weight: 500;
        }

        .bottom {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 12px;
        }

        .price {
            display: flex;
            flex-direction: column;
        }

        .old {
            font-size: 13px;
            text-decoration: line-through;
            color: #a1a1aa;
            margin-bottom: 2px;
        }

        .new {
            font-size: 20px;
            font-weight: 700;
            color: #18181b;
        }

        .btn {
            background: linear-gradient(45deg, #18181b, #27272a);
            color: #fff;
            border: none;
            border-radius: 10px;
            padding: 8px 15px;
            font-size: 13px;
            font-weight: 600;
            cursor: pointer;
            display: flex;
            align-items: center;
            gap: 6px;
            transition: 0.3s;
            box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1);
        }

        .btn:hover {
            background: linear-gradient(45deg, #27272a, #3f3f46);
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.15);
        }

        .btn:before {
            content: "";
            position: absolute;
            top: 0;
            left: -100%;
            width: 100%;
            height: 100%;
            background: linear-gradient(90deg,
                    transparent,
                    rgba(255, 255, 255, 0.1),
                    transparent);
            transition: 0.5s;
        }

        .btn:hover:before {
            left: 100%;
        }

        .icon {
            transition: transform 0.3s;
        }

        .btn:hover .icon {
            transform: rotate(-10deg) scale(1.1);
        }

        .meta {
            display: flex;
            justify-content: space-between;
            align-items: center;
            border-top: 1px solid #f4f4f5;
            padding-top: 12px;
        }

        .rating {
            display: flex;
            align-items: center;
            gap: 2px;
        }

        .rcount {
            margin-left: 6px;
            font-size: 11px;
            color: #71717a;
        }

        .stock {
            font-size: 11px;
            font-weight: 600;
            color: #22c55e;
        }

        @media (max-width: 400px) {
            .card {
                width: 90%;
            }

            .title {
                font-size: 16px;
            }

            .img {
                height: 180px;
            }

            .bottom {
                flex-direction: column;
                align-items: flex-start;
                gap: 10px;
            }

            .price {
                margin-bottom: 5px;
            }

            .btn {
                width: 100%;
                justify-content: center;
            }
        }
    </style>
</head>

<body>
    <div class="card">
        <div class="badge">HOT SALE</div>
        <div class="tilt">
            <div class="img"><img
                    src="https://images.unsplash.com/photo-1544237526-cae15a57ed1e?crop=entropy&cs=srgb&fm=jpg&ixid=M3wzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE3NDkwNDY5NjB8&ixlib=rb-4.1.0&q=85"
                    alt="Premium Laptop"></div>
        </div>
        <div class="info">
            <div class="cat">High-Performance Laptop</div>
            <h2 class="title">UltraBook Pro X</h2>
            <p class="desc">Cutting-edge performance with Intel Core i9, 32GB RAM, and a 1TB SSD in a sleek, lightweight
                design.</p>
            <div class="feats">
                <span class="feat">4K Display</span>
                <span class="feat">16-Hour Battery</span>
                <span class="feat">Thunderbolt 4</span>
            </div>
            <div class="bottom">
                <div class="price">
                    <span class="old">$2,499</span>
                    <span class="new">$1,999</span>
                </div>
                <button class="btn">
                    <span>Add to Cart</span>
                    <svg class="icon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor"
                        stroke-width="2">
                        <path d="M6 2L3 6v14a2 2 0 002 2h14a2 2 0 002-2V6l-3-4" />
                        <line x1="3" y1="6" x2="21" y2="6" />
                        <path d="M16 10a4 4 0 01-8 0" />
                    </svg>
                </button>
            </div>
            <div class="meta">
                <div class="rating">
                    <svg width="16" height="16" viewBox="0 0 24 24" fill="#FFD700" stroke="#FFD700" stroke-width="0.5">
                        <polygon
                            points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2" />
                    </svg>
                    <svg width="16" height="16" viewBox="0 0 24 24" fill="#FFD700" stroke="#FFD700" stroke-width="0.5">
                        <polygon
                            points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2" />
                    </svg>
                    <svg width="16" height="16" viewBox="0 0 24 24" fill="#FFD700" stroke="#FFD700" stroke-width="0.5">
                        <polygon
                            points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2" />
                    </svg>
                    <svg width="16" height="16" viewBox="0 0 24 24" fill="#FFD700" stroke="#FFD700" stroke-width="0.5">
                        <polygon
                            points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2" />
                    </svg>
                    <svg width="16" height="16" viewBox="0 0 24 24" fill="#FFD700" stroke="#FFD700" stroke-width="0.5">
                        <polygon
                            points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2" />
                    </svg>
                    <span class="rcount">245 Reviews</span>
                </div>
                <div class="stock">In Stock</div>
            </div>
        </div>
    </div>
</body>

</html>

HTML

  • card定义了一个产品卡片,包含产品图片、描述、价格、评分等信息。

CSS

  • 全局样式:body设置背景为线性渐变,最小高度为视口高度。
  • 卡片样式:.card定义卡片的基本样式,包括宽度、背景颜色、圆角、阴影、字体系列、外边距、内边距、溢出隐藏和鼠标指针样式。.card:hover定义卡片悬停时的样式,包括变换和阴影效果。
  • 徽章样式:.badge定义徽章的样式,包括位置、背景渐变、颜色、内边距、字体大小、字体粗细、字母间距、文本转换、圆角、阴影和层级。
  • 图片容器样式:.tilt定义图片容器的样式,包括溢出隐藏。.img定义图片的样式,包括高度和溢出隐藏。.img img定义图片的样式,包括宽度、高度、对象适应方式和过渡效果。.card:hover .img img定义卡片悬停时图片的变换效果。
  • 信息区域样式:.info定义信息区域的样式,包括内边距。.cat定义类别的样式,包括字体大小、字体粗细、字母间距、文本转换、颜色和外边距。.title定义标题的样式,包括字体大小、字体粗细、颜色、外边距和字母间距。.desc定义描述的样式,包括字体大小、颜色、行高和外边距。.feats定义特性容器的样式,包括布局、间隙和外边距。.feat定义特性的样式,包括字体大小、背景颜色、颜色、内边距、圆角和字体粗细。
  • 底部样式:.bottom定义底部的样式,包括布局、对齐方式和外边距。.price定义价格容器的样式,包括布局。.old定义原价的样式,包括字体大小、删除线、颜色和外边距。.new定义现价的样式,包括字体大小、字体粗细和颜色。
  • 按钮样式:.btn定义按钮的样式,包括背景渐变、颜色、边框、圆角、内边距、字体大小、字体粗细、鼠标指针样式、布局、间隙、过渡效果和阴影。.btn:hover定义按钮悬停时的样式,包括背景渐变、变换和阴影。.btn:before定义按钮的伪元素样式,包括位置、宽度、高度、背景渐变和过渡效果。.btn:hover:before定义按钮悬停时伪元素的样式,包括位置。.icon定义图标的样式,包括过渡效果。.btn:hover .icon定义按钮悬停时图标的变换效果。
  • 元数据样式:.meta定义元数据容器的样式,包括布局、对齐方式、边框、内边距。.rating定义评分容器的样式,包括布局和间隙。.rcount定义评论数的样式,包括外边距、字体大小和颜色。.stock定义库存状态的样式,包括字体大小、字体粗细和颜色。
  • 响应式样式:@media (max-width: 400px)定义了在小屏幕设备上的响应式样式,包括卡片宽度、标题字体大小、图片高度、底部布局、价格外边距和按钮宽度。

各位互联网搭子,要是这篇文章成功引起了你的注意,别犹豫,关注、点赞、评论、分享走一波,让我们把这份默契延续下去,一起在知识的海洋里乘风破浪!

相关推荐
Yana.nice几秒前
sysctl优先级顺序
服务器·前端·网络
米花丶4 分钟前
异步加载弹出层动画丢失问题
前端
小桥风满袖6 分钟前
Three.js-硬要自学系列31之专项学习动画混合
前端·css·three.js
Lanqing_07609 分钟前
淘宝商品详情图API接口返回参数说明
java·服务器·前端·api·电商
karshey18 分钟前
【Element Plus】Menu组件:url访问页面时高亮对应菜单栏
前端·javascript·vue.js
xiaogg367819 分钟前
系统网站首页三种常见布局vue+elementui
前端·vue.js·elementui
日升23 分钟前
AI 组件库-MateChat × 大模型:DeepSeek、OpenAI 和 阿里通义问 (Qwen)的全流程接入实战(三)
前端·ai编程·trae
Barcke24 分钟前
AI赋能开发者工具:智能提示词编写与项目管理实践
前端·后端
wordbaby29 分钟前
React Router v7 中的 `ErrorBoundary` 详解
前端·react.js