0

[Series 100 Bài Học HTML/CSS Thực Chiến - Bài 48]: Nâng Cấp Khu Vực Flash Sale Với Thanh Chọn 5 Khung Giờ Vàng (Multi-Slot Flash Sale Schedule Tabs) & Chuyển Đổi Trạng Thái "Đang Diễn Ra $\leftrightarrow$ Nhắc Tôi" Bằng CSS Thuần

Chào mừng anh em đã bước sang Bài 48 trong chuỗi 100 Bài Học Làm Chủ HTML/CSS Qua Dự Án Clone Shopee!

Ở Bài 13, chúng ta đã dựng bộ khung cơ bản cho khối Flash Sale trên trang chủ với thanh tiến trình bán chạy "ĐANG BÁN CHẠY" có ngọn lửa bùng cháy. Tuy nhiên, vào những ngày Siêu Sale lớn của Shopee (hoặc khi bạn bấm vào nút "Xem tất cả >" để vào trang chuyên biệt Flash Sale), trải nghiệm săn deal kịch tính hơn gấp bội nhờ Thanh Lịch Trình 5 Khung Giờ Vàng (Flash Sale Time-Slot Schedule Bar):

  • 00:00 — Đã kết thúc / Đang diễn ra

  • 09:00 — Đang diễn ra (Nổi bật với nền Cam Shopee #ee4d2d và mũi tên tam giác chỉ xuống)

  • 12:00 — Sắp diễn ra

  • 18:00 — Sắp diễn ra

  • 21:00 — Ngày mai

Trong Bài 48 hôm nay, chúng ta sẽ nâng cấp toàn diện khu vực Flash Sale với 3 kỹ thuật tương tác CSS đỉnh cao:

  1. Thanh 5 Khung Giờ Vàng Có Mũi Tên Tam Giác Chỉ Xuống (Active Time-Slot Tab with Bottom Pointer): Khi bạn bấm chuyển từ khung 09:00 sang 12:00 hoặc 18:00, ô khung giờ được chọn lập tức đổi sang nền Cam rực rỡ và mọc ra một mũi tên tam giác ở chính giữa cạnh dưới chỉ thẳng xuống danh sách sản phẩm bên dưới!

  2. Chuyển Đổi Danh Sách Sản Phẩm Theo Từng Khung Giờ Bằng CSS Radio Tabs: Bấm vào 09:00 hiển thị các deal đang mở bán (nút cam "Mua Ngay"); bấm sang 12:00 hoặc 18:00 hiển thị các deal sắp mở bán với mức giá bí mật (₫?.990.000) và nút "Nhắc Tôi"!

  3. Nút Bấm "Nhắc Tôi ↔\leftrightarrow Đã Đặt Nhắc Nhở ✓" Có Chuông Rung (@keyframes bellRing): Khi khách hàng bấm vào nút "Nhắc Tôi" ở khung giờ sắp diễn ra, quả chuông sẽ rung lắc nhẹ (rotate) và nút chuyển sang màu xanh ngọc "Đã Nhắc ✓"!

1. Giải phẫu Cấu trúc "Lịch Trình 5 Khung Giờ Flash Sale" (Time-Slot Bar)

Trong thiết kế chiến dịch khuyến mãi giới hạn thời gian (Flash Sale Campaign & Time-Slot UX), việc chia nhỏ các đợt giảm giá theo từng mốc giờ cụ thể giúp tạo cảm giác khan hiếm (FOMO) và kéo người dùng quay lại ứng dụng nhiều lần trong ngày:

image.png

Trên Shopee, thanh chọn 5 khung giờ vàng (.flash-schedule-bar) nằm ngay dưới Header Flash Sale, được chia thành 5 cột bằng nhau (repeat(5, 1fr)) với nền xám than #414141 (trạng thái chờ) và chuyển sang Cam rực rỡ #ee4d2d khi được chọn (:checked):

Plaintext

+-------------------+-------------------+-------------------+-------------------+-------------------+
|       00:00       |       09:00       |       12:00       |       18:00       |       21:00       |
|   Đã kết thúc     |   Đang diễn ra    |    Sắp diễn ra    |    Sắp diễn ra    |     Ngày mai      |
+-------------------+---------▼---------+-------------------+-------------------+-------------------+
  (Nền xám #414141)   (Nền Cam #ee4d2d      (Nền xám #414141)   (Nền xám #414141)   (Nền xám #414141)
                       + Mũi tên ::after)
Thành phần trong .flash-slot-tab Khai báo CSS chuẩn xác Giải thích cơ chế hoạt động
Mũi tên tam giác chỉ xuống ở đáy tab đang chọn (::after) position: absolute; bottom: -0.8rem; left: 50%; transform: translateX(-50%);
border-width: 0.8rem 0.8rem 0;
border-style: solid;
border-color: var(--shopee-primary) transparent transparent transparent;
Dùng kỹ thuật vẽ tam giác bằng Border CSS: Đặt border-top màu cam 8px, hai cạnh trái/phải trong suốt 8px và đặt tại bottom: -0.8rem để nhô xuống dưới đáy tab đang chọn!
Chuyển đổi danh sách sản phẩm theo khung giờ #slot-09:checked ~ .flash-slots-panels .flash-slot-panel--09 { display: grid; } Mỗi khung giờ có một bảng lưới .flash-slot-panel riêng. Mặc định tất cả các bảng đều display: none;, chỉ bảng nào khớp với nút Radio đang :checked mới bật lên!
Giá bí mật của deal sắp mở bán (Upcoming Secret Price) ₫?.850.000 hoặc ₫1.???.000 Kích thích sự tò mò của người săn sale khiến họ bấm nút "Nhắc Tôi" để nhận thông báo khi đến giờ G!

2. Thực hành: Nâng Cấp Khu Vực Flash Sale Đa Khung Giờ (index.html & main.css)

Bước 1: Bổ sung HTML Thanh 5 Khung Giờ & Các Bảng Sản Phẩm Theo Giờ vào index.html

Hãy mở file index.html, tìm đến khu vực Flash Sale (.flash-sale-section - Bài 13) (hoặc đặt ngay bên dưới khối Flash Sale hiện tại để nâng cấp thành phiên bản đầy đủ) và cập nhật cấu trúc Multi-Slot Flash Sale dưới đây:

HTML

        <!-- ================================================================= -->
        <!-- BÀI 48: FLASH SALE ĐA KHUNG GIỜ VÀNG (MULTI-SLOT SCHEDULE TABS)   -->
        <!-- ================================================================= -->
        <section class="flash-sale-pro-section">
            
            <!-- 1. Header Flash Sale + Đồng hồ đếm ngược -->
            <header class="flash-sale-header">
                <div class="flash-sale-header__left">
                    <div class="flash-sale-logo">
                        <span>F<i class="fa-solid fa-bolt"></i>ASH SALE</span>
                    </div>
                    <div class="flash-countdown">
                        <span class="countdown-box">01</span>
                        <span class="countdown-colon">:</span>
                        <span class="countdown-box">42</span>
                        <span class="countdown-colon">:</span>
                        <span class="countdown-box">18</span>
                    </div>
                </div>

                <a href="#" class="section-view-all" style="color: var(--shopee-primary);">
                    Xem tất cả <i class="fa-solid fa-chevron-right"></i>
                </a>
            </header>

            <!-- Hệ thống 5 nút Radio ngầm điều khiển chuyển đổi Khung Giờ Vàng -->
            <input type="radio" name="flash-time-slot" id="slot-00" class="flash-slot-input">
            <input type="radio" name="flash-time-slot" id="slot-09" class="flash-slot-input" checked>
            <input type="radio" name="flash-time-slot" id="slot-12" class="flash-slot-input">
            <input type="radio" name="flash-time-slot" id="slot-18" class="flash-slot-input">
            <input type="radio" name="flash-time-slot" id="slot-21" class="flash-slot-input">

            <!-- 2. THANH CHỌN 5 KHUNG GIỜ VÀNG (SCHEDULE TABS BAR) -->
            <nav class="flash-schedule-bar" aria-label="Khung giờ Flash Sale">
                <label for="slot-00" class="flash-slot-tab">
                    <strong class="slot-time">00:00</strong>
                    <span class="slot-status">Đã kết thúc</span>
                </label>

                <label for="slot-09" class="flash-slot-tab">
                    <strong class="slot-time">09:00</strong>
                    <span class="slot-status">Đang diễn ra</span>
                </label>

                <label for="slot-12" class="flash-slot-tab">
                    <strong class="slot-time">12:00</strong>
                    <span class="slot-status">Sắp diễn ra</span>
                </label>

                <label for="slot-18" class="flash-slot-tab">
                    <strong class="slot-time">18:00</strong>
                    <span class="slot-status">Sắp diễn ra</span>
                </label>

                <label for="slot-21" class="flash-slot-tab">
                    <strong class="slot-time">21:00</strong>
                    <span class="slot-status">Ngày mai</span>
                </label>
            </nav>

            <!-- 3. CÁC BẢNG SẢN PHẨM TƯƠNG ỨNG VỚI TỪNG KHUNG GIỜ -->
            <div class="flash-slots-panels">
                
                <!-- ========================================================= -->
                <!-- BẢNG KHUNG GIỜ 09:00 (ĐANG DIỄN RA - MẶC ĐỊNH HIỂN THỊ)   -->
                <!-- ========================================================= -->
                <div class="flash-slot-panel flash-slot-panel--09">
                    
                    <!-- Deal 09:00 - SP 1 -->
                    <article class="flash-deal-card">
                        <a href="#" class="flash-deal-card__img-wrap">
                            <img src="https://placehold.co/300x300/ee4d2d/ffffff?text=AULA+F75+Pro" alt="AULA F75 Pro" class="flash-deal-card__img">
                            <div class="product-badge-discount">
                                <span class="discount-percent">-45%</span>
                            </div>
                            <span class="flash-mall-ribbon">Mall</span>
                        </a>
                        <div class="flash-deal-card__body">
                            <h3 class="flash-deal-title">Bàn phím cơ không dây AULA F75 Pro 3 Mode Hotswap</h3>
                            <div class="flash-deal-bottom">
                                <div class="flash-deal-price-col">
                                    <span class="flash-price-old">₫1.390.000</span>
                                    <span class="flash-price-now"><small>₫</small>759.000</span>
                                    <!-- Thanh tiến trình bán chạy -->
                                    <div class="flash-progress-bar">
                                        <div class="flash-progress-fill" style="width: 82%;"></div>
                                        <span class="flash-progress-text">ĐANG BÁN CHẠY</span>
                                    </div>
                                </div>
                                <a href="#" class="btn btn--primary flash-buy-btn">Mua Ngay</a>
                            </div>
                        </div>
                    </article>

                    <!-- Deal 09:00 - SP 2 -->
                    <article class="flash-deal-card">
                        <a href="#" class="flash-deal-card__img-wrap">
                            <img src="https://placehold.co/300x300/d0011b/ffffff?text=LG+UltraGear+27" alt="Màn hình LG" class="flash-deal-card__img">
                            <div class="product-badge-discount">
                                <span class="discount-percent">-30%</span>
                            </div>
                            <span class="flash-mall-ribbon">Mall</span>
                        </a>
                        <div class="flash-deal-card__body">
                            <h3 class="flash-deal-title">Màn hình Gaming LG UltraGear 27GS60F-B 180Hz IPS</h3>
                            <div class="flash-deal-bottom">
                                <div class="flash-deal-price-col">
                                    <span class="flash-price-old">₫4.890.000</span>
                                    <span class="flash-price-now"><small>₫</small>3.490.000</span>
                                    <div class="flash-progress-bar">
                                        <div class="flash-progress-fill" style="width: 65%;"></div>
                                        <span class="flash-progress-text">ĐÃ BÁN 142</span>
                                    </div>
                                </div>
                                <a href="#" class="btn btn--primary flash-buy-btn">Mua Ngay</a>
                            </div>
                        </div>
                    </article>

                    <!-- Deal 09:00 - SP 3 (Sắp cháy hàng 94%) -->
                    <article class="flash-deal-card">
                        <a href="#" class="flash-deal-card__img-wrap">
                            <img src="https://placehold.co/300x300/00bfa5/ffffff?text=Anker+GaN+140W" alt="Sạc Anker" class="flash-deal-card__img">
                            <div class="product-badge-discount">
                                <span class="discount-percent">-50%</span>
                            </div>
                            <span class="flash-mall-ribbon">Mall</span>
                        </a>
                        <div class="flash-deal-card__body">
                            <h3 class="flash-deal-title">Củ sạc nhanh Anker Prime 140W GaN 3 Cổng Chính Hãng</h3>
                            <div class="flash-deal-bottom">
                                <div class="flash-deal-price-col">
                                    <span class="flash-price-old">₫2.100.000</span>
                                    <span class="flash-price-now"><small>₫</small>1.050.000</span>
                                    <div class="flash-progress-bar">
                                        <div class="flash-progress-fill" style="width: 94%;"></div>
                                        <span class="flash-progress-text">SẮP CHÁY HÀNG</span>
                                    </div>
                                </div>
                                <a href="#" class="btn btn--primary flash-buy-btn">Mua Ngay</a>
                            </div>
                        </div>
                    </article>

                </div>

                <!-- ========================================================= -->
                <!-- BẢNG KHUNG GIỜ 12:00 & 18:00 (SẮP DIỄN RA - NÚT NHẮC TÔI)  -->
                <!-- ========================================================= -->
                <div class="flash-slot-panel flash-slot-panel--upcoming">
                    
                    <!-- Deal Sắp Diễn Ra 1 (Có nút Nhắc Tôi <-> Đã Nhắc ✓!) -->
                    <article class="flash-deal-card">
                        <a href="#" class="flash-deal-card__img-wrap">
                            <img src="https://placehold.co/300x300/2673dd/ffffff?text=Sony+WH-1000XM5" alt="Tai nghe Sony" class="flash-deal-card__img">
                            <div class="product-badge-discount">
                                <span class="discount-percent">-35%</span>
                            </div>
                            <span class="flash-mall-ribbon">Mall</span>
                        </a>
                        <div class="flash-deal-card__body">
                            <h3 class="flash-deal-title">Tai nghe chống ồn Sony WH-1000XM5 Chính Hãng</h3>
                            <div class="flash-deal-bottom">
                                <div class="flash-deal-price-col">
                                    <span class="flash-price-old">₫7.990.000</span>
                                    <span class="flash-price-now"><small>₫</small>5.???.000</span>
                                    <span class="flash-upcoming-stock">Số lượng mở bán: 50 suất</span>
                                </div>

                                <!-- Nút Nhắc Tôi tương tác bằng Checkbox Hack! -->
                                <label class="flash-remind-toggle">
                                    <input type="checkbox" class="remind-check-input">
                                    <span class="btn flash-remind-btn">
                                        <i class="fa-regular fa-bell remind-bell-icon"></i>
                                        <span class="remind-text-default">Nhắc Tôi</span>
                                        <span class="remind-text-active">Đã Nhắc ✓</span>
                                    </span>
                                </label>
                            </div>
                        </div>
                    </article>

                    <!-- Deal Sắp Diễn Ra 2 -->
                    <article class="flash-deal-card">
                        <a href="#" class="flash-deal-card__img-wrap">
                            <img src="https://placehold.co/300x300/7b1fa2/ffffff?text=Logitech+G+Pro+X" alt="Chuột Logitech" class="flash-deal-card__img">
                            <div class="product-badge-discount">
                                <span class="discount-percent">-42%</span>
                            </div>
                            <span class="flash-mall-ribbon">Mall</span>
                        </a>
                        <div class="flash-deal-card__body">
                            <h3 class="flash-deal-title">Chuột Gaming không dây Logitech G Pro X Superlight 2</h3>
                            <div class="flash-deal-bottom">
                                <div class="flash-deal-price-col">
                                    <span class="flash-price-old">₫3.490.000</span>
                                    <span class="flash-price-now"><small>₫</small>1.???.000</span>
                                    <span class="flash-upcoming-stock">Số lượng mở bán: 30 suất</span>
                                </div>

                                <label class="flash-remind-toggle">
                                    <input type="checkbox" class="remind-check-input" checked>
                                    <span class="btn flash-remind-btn">
                                        <i class="fa-regular fa-bell remind-bell-icon"></i>
                                        <span class="remind-text-default">Nhắc Tôi</span>
                                        <span class="remind-text-active">Đã Nhắc ✓</span>
                                    </span>
                                </label>
                            </div>
                        </div>
                    </article>

                    <!-- Deal Sắp Diễn Ra 3 -->
                    <article class="flash-deal-card">
                        <a href="#" class="flash-deal-card__img-wrap">
                            <img src="https://placehold.co/300x300/ff9800/ffffff?text=iPad+Air+M2+11%22" alt="iPad Air M2" class="flash-deal-card__img">
                            <div class="product-badge-discount">
                                <span class="discount-percent">-22%</span>
                            </div>
                            <span class="flash-mall-ribbon">Mall</span>
                        </a>
                        <div class="flash-deal-card__body">
                            <h3 class="flash-deal-title">Máy tính bảng Apple iPad Air M2 11 inch Wi-Fi 128GB</h3>
                            <div class="flash-deal-bottom">
                                <div class="flash-deal-price-col">
                                    <span class="flash-price-old">₫16.990.000</span>
                                    <span class="flash-price-now"><small>₫</small>12.???.000</span>
                                    <span class="flash-upcoming-stock">Số lượng mở bán: 15 suất</span>
                                </div>

                                <label class="flash-remind-toggle">
                                    <input type="checkbox" class="remind-check-input">
                                    <span class="btn flash-remind-btn">
                                        <i class="fa-regular fa-bell remind-bell-icon"></i>
                                        <span class="remind-text-default">Nhắc Tôi</span>
                                        <span class="remind-text-active">Đã Nhắc ✓</span>
                                    </span>
                                </label>
                            </div>
                        </div>
                    </article>

                </div>

                <!-- ========================================================= -->
                <!-- BẢNG KHUNG GIỜ 00:00 (ĐÃ KẾT THÚC - SOLD OUT OVERLAY)     -->
                <!-- ========================================================= -->
                <div class="flash-slot-panel flash-slot-panel--ended">
                    <article class="flash-deal-card flash-deal-card--ended">
                        <div class="flash-deal-card__img-wrap">
                            <img src="https://placehold.co/300x300/757575/ffffff?text=DEAL+00H+DA+HET" alt="Deal đã kết thúc" class="flash-deal-card__img">
                            <div class="wishlist-soldout-circle">Đã hết lượt</div>
                        </div>
                        <div class="flash-deal-card__body">
                            <h3 class="flash-deal-title">Combo Bàn Phím + Chuột Gaming Không Dây Siêu Tốc</h3>
                            <div class="flash-deal-bottom">
                                <div class="flash-deal-price-col">
                                    <span class="flash-price-old">₫1.290.000</span>
                                    <span class="flash-price-now" style="color: #888;"><small>₫</small>499.000</span>
                                    <span class="flash-upcoming-stock">Khung giờ 00:00 đã kết thúc</span>
                                </div>
                                <button type="button" class="btn flash-buy-btn" disabled style="background-color: #e0e0e0; color: #999; cursor: not-allowed;">Kết Thúc</button>
                            </div>
                        </div>
                    </article>
                </div>

            </div>

        </section>

Bước 2: Viết CSS cho Thanh 5 Khung Giờ & Nút Nhắc Tôi trong ./assets/css/main.css

Hãy mở file main.css, cuộn xuống dưới cùng và bổ sung đoạn code CSS của Bài 48 dưới đây:

CSS

/* Bổ sung vào cuối file ./assets/css/main.css */

/* --- BÀI 48: FLASH SALE ĐA KHUNG GIỜ VÀNG (MULTI-SLOT SCHEDULE TABS) --- */

@keyframes bellRing {
    0%, 100% { transform: rotate(0deg); }
    20% { transform: rotate(22deg); }
    40% { transform: rotate(-18deg); }
    60% { transform: rotate(14deg); }
    80% { transform: rotate(-10deg); }
}

.flash-sale-pro-section {
    background-color: var(--white-color);
    margin-top: 2rem;
    border-radius: 2px;
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

.flash-slot-input {
    display: none;
}

/* ================================================================= */
/* 1. THANH CHỌN 5 KHUNG GIỜ VÀNG (.flash-schedule-bar)              */
/* ================================================================= */
.flash-schedule-bar {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    background-color: #414141;      /* Nền xám than chuẩn thanh khung giờ Flash Sale Shopee */
    color: var(--white-color);
    margin-bottom: 1.6rem;
}

.flash-slot-tab {
    height: 6.4rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    user-select: none;
    position: relative;
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    transition: background-color 0.2s ease;
}

.flash-slot-tab:last-child {
    border-right: none;
}

.flash-slot-tab:hover {
    background-color: #4f4f4f;
}

.slot-time {
    font-size: 2.2rem;
    font-weight: 700;
    line-height: 2.6rem;
    opacity: 0.85;
}

.slot-status {
    font-size: 1.3rem;
    opacity: 0.75;
    margin-top: 0.2rem;
}

/* BÍ THUẬT: KHI KHUNG GIỜ ĐƯỢC CHỌN (:checked) -> Nền Cam Shopee + Mũi tên tam giác chỉ xuống! */
#slot-00:checked ~ .flash-schedule-bar label[for="slot-00"],
#slot-09:checked ~ .flash-schedule-bar label[for="slot-09"],
#slot-12:checked ~ .flash-schedule-bar label[for="slot-12"],
#slot-18:checked ~ .flash-schedule-bar label[for="slot-18"],
#slot-21:checked ~ .flash-schedule-bar label[for="slot-21"] {
    background-color: var(--shopee-primary);
}

#slot-00:checked ~ .flash-schedule-bar label[for="slot-00"] .slot-time,
#slot-09:checked ~ .flash-schedule-bar label[for="slot-09"] .slot-time,
#slot-12:checked ~ .flash-schedule-bar label[for="slot-12"] .slot-time,
#slot-18:checked ~ .flash-schedule-bar label[for="slot-18"] .slot-time,
#slot-21:checked ~ .flash-schedule-bar label[for="slot-21"] .slot-time,
#slot-00:checked ~ .flash-schedule-bar label[for="slot-00"] .slot-status,
#slot-09:checked ~ .flash-schedule-bar label[for="slot-09"] .slot-status,
#slot-12:checked ~ .flash-schedule-bar label[for="slot-12"] .slot-status,
#slot-18:checked ~ .flash-schedule-bar label[for="slot-18"] .slot-status,
#slot-21:checked ~ .flash-schedule-bar label[for="slot-21"] .slot-status {
    opacity: 1;
}

/* Vẽ mũi tên tam giác màu cam nhô xuống dưới đáy tab đang chọn */
#slot-00:checked ~ .flash-schedule-bar label[for="slot-00"]::after,
#slot-09:checked ~ .flash-schedule-bar label[for="slot-09"]::after,
#slot-12:checked ~ .flash-schedule-bar label[for="slot-12"]::after,
#slot-18:checked ~ .flash-schedule-bar label[for="slot-18"]::after,
#slot-21:checked ~ .flash-schedule-bar label[for="slot-21"]::after {
    content: "";
    position: absolute;
    bottom: -0.8rem;
    left: 50%;
    transform: translateX(-50%);
    border-width: 0.8rem 0.8rem 0;
    border-style: solid;
    border-color: var(--shopee-primary) transparent transparent transparent;
    z-index: 2;
}

/* ================================================================= */
/* 2. CHUYỂN ĐỔI BẢNG SẢN PHẨM THEO KHUNG GIỜ BẰNG CSS THUẦN         */
/* ================================================================= */
.flash-slots-panels {
    padding: 0.8rem 2rem 2.4rem;
}

.flash-slot-panel {
    display: none;                  /* Mặc định ẩn tất cả các bảng */
    grid-template-columns: repeat(3, 1fr);
    gap: 1.6rem;
    animation: fadeIn ease 0.25s;
}

/* Bật đúng bảng sản phẩm tương ứng với nút Radio khung giờ đang chọn! */
#slot-09:checked ~ .flash-slots-panels .flash-slot-panel--09 {
    display: grid;
}

#slot-12:checked ~ .flash-slots-panels .flash-slot-panel--upcoming,
#slot-18:checked ~ .flash-slots-panels .flash-slot-panel--upcoming,
#slot-21:checked ~ .flash-slots-panels .flash-slot-panel--upcoming {
    display: grid;
}

#slot-00:checked ~ .flash-slots-panels .flash-slot-panel--ended {
    display: grid;
}

/* ================================================================= */
/* 3. THẺ DEAL FLASH SALE CHI TIẾT (.flash-deal-card)                */
/* ================================================================= */
.flash-deal-card {
    background-color: var(--white-color);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 2px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.flash-deal-card:hover {
    transform: translateY(-0.2rem);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.flash-deal-card__img-wrap {
    width: 100%;
    aspect-ratio: 1 / 1;
    position: relative;
    display: block;
    overflow: hidden;
}

.flash-deal-card__img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.flash-mall-ribbon {
    position: absolute;
    top: 0.8rem;
    left: 0.8rem;
    background-color: var(--shopee-mall-red);
    color: var(--white-color);
    font-size: 1.1rem;
    font-weight: 700;
    padding: 0.1rem 0.6rem;
    border-radius: 2px;
}

.flash-deal-card__body {
    padding: 1.4rem;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.flash-deal-title {
    font-size: 1.45rem;
    font-weight: 400;
    color: var(--text-primary);
    line-height: 2rem;
    margin-bottom: 1.4rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.flash-deal-bottom {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
}

.flash-deal-price-col {
    flex: 1;
}

.flash-price-old {
    display: block;
    font-size: 1.3rem;
    color: var(--text-secondary);
    text-decoration: line-through;
}

.flash-price-now {
    display: block;
    font-size: 2rem;
    font-weight: 500;
    color: var(--shopee-primary);
    margin: 0.2rem 0 0.8rem;
}

.flash-price-now small {
    font-size: 1.4rem;
    margin-right: 0.1rem;
}

/* Thanh tiến trình bán chạy bên trong thẻ Deal */
.flash-progress-bar {
    width: 100%;
    height: 1.6rem;
    background-color: #ffbda6;
    border-radius: 0.8rem;
    position: relative;
    overflow: hidden;
}

.flash-progress-fill {
    height: 100%;
    background-image: linear-gradient(90deg, #ff7337 0%, #ee4d2d 100%);
    border-radius: 0.8rem;
}

.flash-progress-text {
    position: absolute;
    inset: 0;
    color: var(--white-color);
    font-size: 1rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    letter-spacing: 0.03rem;
}

.flash-buy-btn {
    min-width: 9.2rem;
    height: 3.4rem;
    font-size: 1.35rem;
    padding: 0 1rem;
    flex-shrink: 0;
}

/* --- NÚT BẤM "NHẮC TÔI <-> ĐÃ NHẮC ✓" CHO KHUNG GIỜ SẮP DIỄN RA --- */
.flash-upcoming-stock {
    display: block;
    font-size: 1.2rem;
    color: #00bfa5;
    font-weight: 500;
}

.flash-remind-toggle {
    cursor: pointer;
    user-select: none;
    flex-shrink: 0;
}

.remind-check-input {
    display: none;
}

.flash-remind-btn {
    min-width: 9.6rem;
    height: 3.4rem;
    background-color: var(--white-color);
    border: 1px solid var(--shopee-primary);
    color: var(--shopee-primary);
    font-size: 1.3rem;
    padding: 0 1rem;
    gap: 0.5rem;
    transition: all 0.2s ease;
}

.flash-remind-btn:hover {
    background-color: var(--shopee-primary-light);
}

.remind-text-active {
    display: none;
}

/* Khi bấm nút Nhắc Tôi (:checked) -> Rung quả chuông & Đổi sang màu Xanh Ngọc Đã Nhắc! */
.remind-check-input:checked + .flash-remind-btn {
    border-color: #00bfa5;
    background-color: #e6f8f5;
    color: #00bfa5;
}

.remind-check-input:checked + .flash-remind-btn .remind-bell-icon {
    animation: bellRing 0.5s ease;
}

.remind-check-input:checked + .flash-remind-btn .remind-text-default {
    display: none;
}

.remind-check-input:checked + .flash-remind-btn .remind-text-active {
    display: inline;
}

Bước 3: Bổ sung quy tắc Responsive cho Thanh Khung Giờ Flash Sale trong ./assets/css/responsive.css

Trên màn hình Điện thoại (<= 739px), chúng ta chuyển lưới 3 cột sản phẩm Flash Sale sang xếp dọc 1 cột card ngang hoặc 2 cột gọn gàng:

CSS

/* Bổ sung vào cuối khối @media (max-width: 739px) trong ./assets/css/responsive.css */
    .flash-slot-tab {
        height: 5.4rem;
    }

    .slot-time {
        font-size: 1.6rem;
    }

    .slot-status {
        font-size: 1.1rem;
    }

    .flash-slots-panels {
        padding: 0.4rem 1.2rem 1.6rem;
    }

    .flash-slot-panel {
        grid-template-columns: 1fr;
    }

3. Giải mã dòng code: 3 Điểm sáng Kỹ thuật trong Bài 48

  1. Khả năng ánh xạ "Nhiều nút Radio tới cùng 1 Bảng hiển thị" (#slot-12:checked ~ ..., #slot-18:checked ~ ..., #slot-21:checked ~ ...):

    • Trong thực tế, các khung giờ tương lai (12:00, 18:00, 21:00) đều dùng chung một giao diện hiển thị giá bí mật (₫5.???.000) và nút "Nhắc Tôi".

    • Thay vì phải nhân bản 3 lần cùng một đoạn HTML giống hệt nhau cho 3 khung giờ đó, chúng ta dùng dấu phẩy (,) để gộp cả 3 bộ chọn #slot-12:checked, #slot-18:checked, #slot-21:checked cùng kích hoạt .flash-slot-panel--upcoming! Mã nguồn gọn nhẹ mà vẫn hoạt động trên cả 5 khung giờ!

  2. Hiệu ứng quả chuông rung lắc (@keyframes bellRing) khi bấm "Nhắc Tôi":

    • Khi người dùng click vào nút "Nhắc Tôi", quả chuông nhỏ bên trái chữ lập tức lắc lư qua lại các góc +22deg →\rightarrow -18deg →\rightarrow +14deg →\rightarrow -10deg và chuyển sang trạng thái "Đã Nhắc ✓" màu xanh ngọc #00bfa5.
  3. Mũi tên tam giác chỉ điểm bằng Border CSS (border-color: var(--shopee-primary) transparent transparent transparent):

    • Kết hợp bottom: -0.8rem; left: 50%; transform: translateX(-50%);, mũi tên tam giác màu cam luôn bám chặt ngay chính giữa cạnh dưới của khung giờ đang chọn, dẫn dắt ánh nhìn của người mua xuống thẳng danh sách deal bên dưới!

4. Bài tập trải nghiệm thực tế & Hẹn gặp ở Bài 49!

Hãy lưu lại toàn bộ các file (index.html, main.css, responsive.css) và nhấn F5 trên trình duyệt!

  1. Cuộn tới khu vực Flash Sale Đa Khung Giờ Vàng (Bài 48):

    • Mặc định khung 09:00 Đang diễn ra đang sáng cam với mũi tên tam giác chỉ xuống 3 deal đang mở bán (AULA F75 Pro, Màn hình LG, Củ sạc Anker).

    • Hãy click chuột sang khung 12:00 Sắp diễn ra (hoặc 18:00): Mũi tên cam lập tức nhảy sang tab mới và danh sách bên dưới đổi thành các deal giá bí mật kèm nút "Nhắc Tôi"! Hãy bấm thử vào nút "Nhắc Tôi" để xem quả chuông rung lên và đổi sang "Đã Nhắc ✓"!

    • Hãy click chuột sang khung 00:00 Đã kết thúc: Hiển thị ngay trạng thái deal đã hết lượt với vòng tròn đen mờ!

Ở Bài 49, chúng ta sẽ tiếp tục thiết kế một trạng thái giao diện cực kỳ quan trọng nhưng hay bị các lập trình viên mới bỏ quên: Giao Diện Trạng Thái Trống & Không Tìm Thấy Kết Quả (Empty Search Result & Empty Cart States) — gồm minh họa kính lúp không tìm thấy kết quả kèm gợi ý từ khóa, và giao diện Giỏ hàng trống trơn với nút "MUA NGAY"!


All rights reserved

Viblo
Hãy đăng ký một tài khoản Viblo để nhận được nhiều bài viết thú vị hơn.
Đăng kí