HTML+CSS 实现产品小米产品展示效果

效果

 完整代码

HTML:

<div class="top-nav">
        <div class="nav">
            <div class="nav-item active" data-index="0">全网热卖</div>
            <div class="nav-item" data-index="1">小米影像</div>
            <div class="nav-item" data-index="2">百度百科</div>
            <div class="nav-item" data-index="3">视频专区</div>
            <div class="nav-item" data-index="4">品牌图片</div>
        </div>
        <input type="text" class="search-box" placeholder="搜索商品">
    </div>
    
    <div class="content-carousel">
        <div class="carousel-inner">
            <div class="carousel-item active" id="hot-sales">
                <div class="product-grid">
                    <!-- 热卖产品将通过JavaScript动态生成 -->
                </div>
            </div>
            <div class="carousel-item" id="xiaomi-image">
                <h2>小米影像</h2>
                <p>这里展示小米的影像技术和产品。</p>
                <img src="/api/placeholder/600/400" alt="小米影像技术展示">
            </div>
            <div class="carousel-item" id="baidu-baike">
                <h2>百度百科</h2>
                <p>这里可以放置小米相关的百度百科内容。</p>
                <div>小米是一家专注于智能硬件和电子产品研发的公司,成立于2010年...</div>
            </div>
            <div class="carousel-item" id="video-section">
                <h2>视频专区</h2>
                <p>这里可以展示小米产品的视频介绍。</p>
                <div style="background-color: #ddd; width: 640px; height: 360px; margin: 20px auto; display: flex; justify-content: center; align-items: center;">
                    视频播放器占位符
                </div>
            </div>
            <div class="carousel-item" id="brand-images">
                <h2>品牌图片</h2>
                <p>这里展示小米的品牌形象和产品图片。</p>
                <div style="display: flex; justify-content: space-around; flex-wrap: wrap;">
                    <img src="/api/placeholder/200/200" alt="小米Logo">
                    <img src="/api/placeholder/200/200" alt="小米产品展示1">
                    <img src="/api/placeholder/200/200" alt="小米产品展示2">
                </div>
            </div>
        </div>
    </div>

css

<style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 20px;
            background-color: #f4f4f4;
        }
        .top-nav {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
        }
        .nav {
            display: flex;
        }
        .nav-item {
            padding: 10px 15px;
            cursor: pointer;
            border-bottom: 2px solid transparent;
            transition: all 0.3s ease;
        }
        .nav-item.active {
            border-bottom-color: #ff6700;
            color: #ff6700;
        }
        .search-box {
            padding: 5px;
            border: 1px solid #ddd;
            border-radius: 4px;
        }
        .content-carousel {
            position: relative;
            overflow: hidden;
        }
        .carousel-inner {
            display: flex;
            transition: transform 0.5s ease-in-out;
        }
        .carousel-item {
            min-width: 100%;
            display: none;
        }
        .carousel-item.active {
            display: block;
        }
        .product-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
            gap: 20px;
        }
        .product-card {
            background: white;
            border-radius: 8px;
            padding: 15px;
            text-align: center;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
            transition: all 0.3s ease;
        }
        .product-card:hover {
            transform: translateY(-5px) scale(1.03);
            box-shadow: 0 4px 8px rgba(0,0,0,0.2);
        }
        .product-card img {
            max-width: 100%;
            height: 150px;
            object-fit: contain;
            transition: transform 0.3s ease;
        }
        .product-card:hover img {
            transform: scale(1.05);
        }
        .product-name {
            margin: 10px 0;
            font-weight: bold;
        }
        .product-price {
            color: #ff6700;
            font-weight: bold;
            margin-bottom: 10px;
        }
        .buy-button {
            background-color: #ff6700;
            color: white;
            border: none;
            padding: 8px 15px;
            border-radius: 4px;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }
        .buy-button:hover {
            background-color: #ff8533;
        }
    </style>

 Javascript :

<script>
        // 产品数据
        const products = [
            { name: "Xiaomi MIX Fold 4", price: 8999, image: "./img/1.png" },
            { name: "Xiaomi MIX Flip", price: 5999, image: "./img/1.png" },
            { name: "Xiaomi Watch S4 Sport", price: 1999, image: "./img/1.png" },
            { name: "小米手环9", price: 249, image: "./img/1.png" },
            { name: "Xiaomi Buds 5", price: 699, image: "./img/1.png" },
            { name: "小米创业思考", price: 86, image: "./img/1.png" },
            { name: "Civi 4 Pro 迪士尼限定版", price: 3299, image: "./img/1.png" },
            { name: "Xiaomi 14 Ultra", price: 6499, image: "./img/1.png" },
            { name: "Xiaomi Pad 6S Pro 12.4", price: 3299, image: "./img/1.png" },
            { name: "Redmi Turbo 3", price: 1999, image: "./img/1.png" },
        ];

        // 生成产品卡片
        function generateProductCards() {
            const productGrid = document.querySelector('#hot-sales .product-grid');
            productGrid.innerHTML = products.map(product => `
                <div class="product-card">
                    <img src="${product.image}" alt="${product.name}">
                    <div class="product-name">${product.name}</div>
                    <div class="product-price">¥${product.price}</div>
                    <button class="buy-button">立即购买</button>
                </div>
            `).join('');
        }

        // 初始化页面
        generateProductCards();

        // 导航和轮播功能
        const navItems = document.querySelectorAll('.nav-item');
        const carouselItems = document.querySelectorAll('.carousel-item');
        const carousel = document.querySelector('.carousel-inner');

        function showSlide(index) {
            navItems.forEach((item, i) => {
                item.classList.toggle('active', i === index);
            });
            carouselItems.forEach((item, i) => {
                if (i === index) {
                    item.style.display = 'block';
                } else {
                    item.style.display = 'none';
                }
            });
        }

        navItems.forEach((item, index) => {
            item.addEventListener('click', () => {
                showSlide(index);
            });
        });

        // 搜索功能(简单实现)
        const searchBox = document.querySelector('.search-box');
        searchBox.addEventListener('input', (e) => {
            const searchTerm = e.target.value.toLowerCase();
            const productCards = document.querySelectorAll('.product-card');
            productCards.forEach(card => {
                const productName = card.querySelector('.product-name').textContent.toLowerCase();
                card.style.display = productName.includes(searchTerm) ? 'block' : 'none';
            });
        });
    </script>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

耀南.

你的鼓励将是我最最最最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值