[Series 100 Bài Học HTML/CSS Thực Chiến - Bài 74]: Xây Dựng Khu Vực "Shopee Mall — Cổng Thương Hiệu Chính Hãng" (Brand Showcase Grid) Với Lưới Logo Đối Tác & Hiệu Ứng Lật Thẻ 3D (3D Flip Card) Bằng CSS Thuần
Chào mừng anh em đã bước sang Bài 74 trong chuỗi 100 Bài Học Làm Chủ HTML/CSS Qua Dự Án Clone Shopee!
Ở Bài 73, chúng ta đã hoàn thành Shopee Video với đường ray lướt dọc Vertical Scroll Snap và đĩa nhạc xoay tròn. Hôm nay, chúng ta sẽ xây dựng một phân khu mang sắc Đỏ Đô (#d0011b) sang trọng, tôn vinh các thương hiệu đối tác hàng đầu trên sàn: Khu Vực "Shopee Mall — Cổng Thương Hiệu Chính Hãng" (Brand Showcase Grid) với Hiệu Ứng Lật Thẻ 3D (3D Flip Card)!
Khi người dùng rê chuột (hoặc chạm trên điện thoại) vào từng tấm thẻ thương hiệu (AULA, Sony, LG, Anker), thay vì chỉ phóng to ảnh đơn điệu, toàn bộ tấm thẻ sẽ lật xoay 180° trong không gian 3D để hé lộ Mặt Sau chứa Mã Giảm Giá Độc Quyền Của Hãng và nút "Vào Gian Hàng"!
Trong Bài 74, chúng ta sẽ làm chủ 3 kỹ thuật đồ họa 3D CSS thuần cực kỳ đắt giá:
-
Tam Giác Vàng Của 3D Flip Card (
perspective+transform-style: preserve-3d+backface-visibility: hidden): Giúp 2 mặt trước/sau nằm dính lưng vào nhau như một tấm danh thiếp thật — khi lật qua góc 90°, mặt trước tự động ẩn đi và mặt sau hiện ra mượt mà, không bao giờ bị lộn ngược chữ! -
Thanh 3 Cam Kết Vàng Của Shopee Mall: Tái hiện dải cam kết đặc trưng ngay trên Header Mall (Trả hàng miễn phí 15 ngày · Hàng chính hãng 100% · Miễn phí vận chuyển).
-
Hỗ Trợ Cả Chuột (
:hover) Lẫn Bàn Phím / Cảm Ứng (:focus-within) & Dark Mode (Bài 55): Đảm bảo hiệu ứng lật 3D hoạt động trơn tru trên mọi thiết bị và đồng bộ màu sắc khi bật chế độ tối.
1. Giải phẫu Khu Vực Shopee Mall & Cơ Chế Lật Thẻ 3D (rotateY(180deg))
Hãy quan sát diện mạo đặc trưng của khu vực Shopee Mall — Gian Hàng Chính Hãng với dải cam kết màu đỏ đô và lưới thương hiệu đối tác nổi bật:

Mỗi thẻ thương hiệu .mall-flip-card được cấu tạo từ 3 lớp lồng nhau để tạo ra chiều sâu phối cảnh 3D chuẩn xác:
Plaintext
MẶT TRƯỚC (.mall-flip-front) MẶT SAU (.mall-flip-back - rotateY(180deg))
+-----------------------------+ +-----------------------------+
| [ Mall ] | | ƯU ĐÃI ĐỘC QUYỀN HÃNG |
| | Hover / Tap | |
| [ 🖼️ LOGO / SP ] | ═══════════► | GIẢM 15% TỐI ĐA |
| | rotateY(180°) | ₫150.000 |
| AULA Official Store | | Mã: AULAMALL15 |
| Ưu đãi đến 40% | | [ Vào Gian Hàng Mall → ] |
+-----------------------------+ +-----------------------------+
| Thành phần trong 3D Flip Card | Khai báo CSS cốt lõi | Tại sao thiếu 1 trong 3 dòng này thẻ sẽ lỗi? |
|---|---|---|
| 1. Khung sân khấu ( .mall-flip-card) |
perspective: 100rem; |
Tạo độ sâu không gian 3D. Nếu thiếu perspective, thẻ chỉ bị bẹp ngang như tờ giấy 2D chứ không có cảm giác xoay nổi khỏi màn hình! |
| 2. Trục xoay chung ( .mall-flip-inner) |
transform-style: preserve-3d;transition: transform 0.65s cubic-bezier(0.4, 0, 0.2, 1); |
Giữ cho cả mặt trước và mặt sau cùng tồn tại trong không gian 3D thay vì bị ép phẳng vào cùng một mặt phẳng. |
| 3. Hai mặt thẻ ( .mall-flip-face) |
position: absolute; inset: 0;backface-visibility: hidden; |
backface-visibility: hidden là chìa khóa: nó tự động ẩn lưng của mặt trước khi xoay quá 90° để nhường chỗ cho mặt sau (đã xoay sẵn rotateY(180deg)) lộ diện đúng chiều chữ! |
2. Thực hành: Code Khu Vực "Shopee Mall & 3D Flip Cards" (index.html & main.css)
Bước 1: Bổ sung HTML Khối Cổng Thương Hiệu Shopee Mall (.mall-showcase-section) vào index.html
Hãy mở file index.html, tìm đến bên trong <div class="shopee-container grid-container"> (ngay bên dưới khối Shopee Video của Bài 73) và chèn toàn bộ cấu trúc Bài 74: Shopee Mall — Cổng Thương Hiệu Chính Hãng dưới đây:
HTML
<!-- ================================================================= -->
<!-- BÀI 74: SHOPEE MALL - CỔNG THƯƠNG HIỆU CHÍNH HÃNG (3D FLIP CARD) -->
<!-- ================================================================= -->
<section class="mall-showcase-section">
<!-- 1. Header Shopee Mall Kèm 3 Cam Kết Vàng -->
<header class="mall-showcase-header">
<div class="mall-header__left">
<h2 class="mall-brand-heading">SHOPEE MALL</h2>
<div class="mall-guarantees">
<span class="mall-guarantee-item">
<i class="fa-solid fa-rotate-left"></i> Trả hàng miễn phí 15 ngày
</span>
<span class="mall-guarantee-item">
<i class="fa-solid fa-shield-check"></i> Hàng chính hãng 100%
</span>
<span class="mall-guarantee-item">
<i class="fa-solid fa-truck-fast"></i> Miễn phí vận chuyển
</span>
</div>
</div>
<a href="#" class="mall-view-all">
Xem Tất Cả <span class="mall-arrow-circle"><i class="fa-solid fa-chevron-right"></i></span>
</a>
</header>
<!-- 2. LƯỚI 4 THẺ THƯƠNG HIỆU LẬT 3D (.mall-flip-grid) -->
<div class="mall-flip-grid">
<!-- THẺ 3D 1: AULA OFFICIAL STORE -->
<article class="mall-flip-card" tabindex="0">
<div class="mall-flip-inner">
<!-- Mặt trước -->
<div class="mall-flip-face mall-flip-front">
<span class="mall-front-badge">Mall</span>
<div class="mall-front-visual">
<img src="https://placehold.co/320x220/fff0ec/ee4d2d?text=AULA+F75+Pro" alt="AULA Official" class="mall-front-img">
<div class="mall-logo-pill">AULA</div>
</div>
<div class="mall-front-info">
<h3 class="mall-front-title">AULA Official Store VN</h3>
<p class="mall-front-promo">Siêu sale Gaming Gear đến 40%</p>
</div>
</div>
<!-- Mặt sau (Hiện ra khi lật 180 độ) -->
<div class="mall-flip-face mall-flip-back">
<span class="mall-back-tag">ƯU ĐÃI ĐỘC QUYỀN MALL</span>
<strong class="mall-back-deal">Giảm ₫150.000</strong>
<p class="mall-back-cond">Cho đơn bàn phím cơ từ ₫800k · Bảo hành 12 tháng 1 đổi 1</p>
<div class="mall-back-code">Mã: <strong>AULAMALL15</strong></div>
<a href="#" class="btn mall-back-btn">Vào Gian Hàng <i class="fa-solid fa-arrow-right"></i></a>
</div>
</div>
</article>
<!-- THẺ 3D 2: SONY OFFICIAL STORE -->
<article class="mall-flip-card" tabindex="0">
<div class="mall-flip-inner">
<div class="mall-flip-face mall-flip-front">
<span class="mall-front-badge">Mall</span>
<div class="mall-front-visual">
<img src="https://placehold.co/320x220/ebf3ff/2673dd?text=SONY+WH-1000XM5" alt="Sony Official" class="mall-front-img">
<div class="mall-logo-pill">SONY</div>
</div>
<div class="mall-front-info">
<h3 class="mall-front-title">Sony Electronics VN</h3>
<p class="mall-front-promo">Âm thanh đỉnh cao · Trả góp 0%</p>
</div>
</div>
<div class="mall-flip-face mall-flip-back mall-flip-back--blue">
<span class="mall-back-tag">ƯU ĐÃI ĐỘC QUYỀN MALL</span>
<strong class="mall-back-deal">Giảm ₫500.000</strong>
<p class="mall-back-cond">Áp dụng dòng tai nghe chống ồn WH-1000XM5 & WF-1000XM5</p>
<div class="mall-back-code">Mã: <strong>SONYMALL500</strong></div>
<a href="#" class="btn mall-back-btn">Vào Gian Hàng <i class="fa-solid fa-arrow-right"></i></a>
</div>
</div>
</article>
<!-- THẺ 3D 3: LG ULTRAGEAR OFFICIAL -->
<article class="mall-flip-card" tabindex="0">
<div class="mall-flip-inner">
<div class="mall-flip-face mall-flip-front">
<span class="mall-front-badge">Mall</span>
<div class="mall-front-visual">
<img src="https://placehold.co/320x220/fde8ec/d0011b?text=LG+UltraGear+180Hz" alt="LG Official" class="mall-front-img">
<div class="mall-logo-pill">LG</div>
</div>
<div class="mall-front-info">
<h3 class="mall-front-title">LG Official Flagship</h3>
<p class="mall-front-promo">Màn hình Gaming giảm đến 25%</p>
</div>
</div>
<div class="mall-flip-face mall-flip-back">
<span class="mall-back-tag">ƯU ĐÃI ĐỘC QUYỀN MALL</span>
<strong class="mall-back-deal">Giảm ₫300.000</strong>
<p class="mall-back-cond">Tặng kèm giá treo màn hình Human Motion cho đơn từ ₫3,5Tr</p>
<div class="mall-back-code">Mã: <strong>LGGEAR300</strong></div>
<a href="#" class="btn mall-back-btn">Vào Gian Hàng <i class="fa-solid fa-arrow-right"></i></a>
</div>
</div>
</article>
<!-- THẺ 3D 4: ANKER OFFICIAL STORE -->
<article class="mall-flip-card" tabindex="0">
<div class="mall-flip-inner">
<div class="mall-flip-face mall-flip-front">
<span class="mall-front-badge">Mall</span>
<div class="mall-front-visual">
<img src="https://placehold.co/320x220/e6f8f5/00bfa5?text=ANKER+Prime+140W" alt="Anker Official" class="mall-front-img">
<div class="mall-logo-pill">ANKER</div>
</div>
<div class="mall-front-info">
<h3 class="mall-front-title">Anker Official Store</h3>
<p class="mall-front-promo">Sạc nhanh GaN · Bảo hành 18T</p>
</div>
</div>
<div class="mall-flip-face mall-flip-back mall-flip-back--teal">
<span class="mall-back-tag">ƯU ĐÃI ĐỘC QUYỀN MALL</span>
<strong class="mall-back-deal">Giảm 20%</strong>
<p class="mall-back-cond">Tối đa ₫200k cho bộ củ sạc & cáp bọc dù Anker Prime</p>
<div class="mall-back-code">Mã: <strong>ANKERGAN20</strong></div>
<a href="#" class="btn mall-back-btn">Vào Gian Hàng <i class="fa-solid fa-arrow-right"></i></a>
</div>
</div>
</article>
</div>
</section>
Bước 2: Viết CSS cho Khu Vực Shopee Mall & Hiệu Ứng 3D Flip Card 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 74 dưới đây:
CSS
/* Bổ sung vào cuối file ./assets/css/main.css */
/* --- BÀI 74: SHOPEE MALL - CỔNG THƯƠNG HIỆU CHÍNH HÃNG (3D FLIP CARD) --- */
.mall-showcase-section {
background-color: var(--white-color);
margin-top: 2rem;
border-radius: 4px;
box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
overflow: hidden;
}
/* 1. Header Shopee Mall & 3 Cam kết vàng */
.mall-showcase-header {
padding: 1.8rem 2.4rem;
border-bottom: 1px solid var(--border-subtle, #eeeeee);
display: flex;
align-items: center;
justify-content: space-between;
flex-wrap: wrap;
gap: 1.4rem;
}
.mall-header__left {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 2rem;
}
.mall-brand-heading {
font-size: 1.8rem;
font-weight: 800;
color: #d0011b;
letter-spacing: 0.04rem;
padding-right: 2rem;
border-right: 1px solid var(--border-subtle, #dcdcdc);
}
.mall-guarantees {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 1.8rem;
}
.mall-guarantee-item {
font-size: 1.35rem;
color: var(--text-primary);
display: inline-flex;
align-items: center;
gap: 0.6rem;
}
.mall-guarantee-item i {
color: #d0011b;
font-size: 1.45rem;
}
.mall-view-all {
font-size: 1.4rem;
font-weight: 500;
color: #d0011b;
display: inline-flex;
align-items: center;
gap: 0.7rem;
}
.mall-arrow-circle {
width: 2rem;
height: 2rem;
border-radius: 50%;
background-color: #d0011b;
color: #ffffff;
font-size: 1rem;
display: inline-flex;
align-items: center;
justify-content: center;
}
/* ================================================================= */
/* 2. LƯỚI 4 THẺ THƯƠNG HIỆU LẬT 3D (3D FLIP CARD CSS THUẦN) */
/* ================================================================= */
.mall-flip-grid {
padding: 2.4rem;
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 2rem;
}
/* Sân khấu 3D: Khai báo perspective để tạo độ sâu khi xoay */
.mall-flip-card {
height: 27.6rem;
perspective: 100rem;
outline: none;
cursor: pointer;
}
/* Trục xoay chung của cả 2 mặt thẻ */
.mall-flip-inner {
width: 100%;
height: 100%;
position: relative;
transform-style: preserve-3d;
transition: transform 0.65s cubic-bezier(0.4, 0, 0.2, 1);
}
/* Lật 180 độ khi rê chuột (:hover) hoặc chạm/focus bàn phím (:focus-within)! */
.mall-flip-card:hover .mall-flip-inner,
.mall-flip-card:focus-within .mall-flip-inner {
transform: rotateY(180deg);
}
/* Quy tắc chung cho cả Mặt Trước và Mặt Sau */
.mall-flip-face {
position: absolute;
inset: 0;
border-radius: 8px;
overflow: hidden;
-webkit-backface-visibility: hidden;
backface-visibility: hidden; /* BÍ THUẬT: Ẩn lưng thẻ khi xoay quá 90 độ! */
border: 1px solid var(--border-subtle, rgba(0, 0, 0, 0.08));
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
}
/* MẶT TRƯỚC: Ảnh sản phẩm đại diện + Logo thương hiệu */
.mall-flip-front {
background-color: var(--white-color);
display: flex;
flex-direction: column;
}
.mall-front-badge {
position: absolute;
top: 1rem;
left: 1rem;
z-index: 2;
background-color: #d0011b;
color: #ffffff;
font-size: 1.1rem;
font-weight: 700;
padding: 0.2rem 0.8rem;
border-radius: 2px;
}
.mall-front-visual {
height: 17.6rem;
position: relative;
background-color: var(--bg-elevated, #f8f8f8);
}
.mall-front-img {
width: 100%;
height: 100%;
object-fit: cover;
}
.mall-logo-pill {
position: absolute;
bottom: -1.6rem;
left: 50%;
transform: translateX(-50%);
background-color: #ffffff;
color: #222222;
border: 1px solid rgba(0, 0, 0, 0.1);
box-shadow: 0 3px 8px rgba(0, 0, 0, 0.12);
font-size: 1.35rem;
font-weight: 800;
letter-spacing: 0.08rem;
padding: 0.5rem 1.8rem;
border-radius: 2rem;
white-space: nowrap;
}
.mall-front-info {
flex: 1;
padding: 2.4rem 1.4rem 1.4rem;
text-align: center;
display: flex;
flex-direction: column;
justify-content: center;
}
.mall-front-title {
font-size: 1.45rem;
font-weight: 600;
color: var(--text-primary);
margin-bottom: 0.4rem;
}
.mall-front-promo {
font-size: 1.25rem;
font-weight: 500;
color: #d0011b;
}
/* MẶT SAU: Xoay sẵn 180 độ úp lưng vào mặt trước */
.mall-flip-back {
transform: rotateY(180deg);
background-image: linear-gradient(145deg, #d0011b 0%, #ee4d2d 100%);
color: #ffffff;
padding: 2.2rem 1.8rem;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
text-align: center;
gap: 1rem;
}
.mall-flip-back--blue {
background-image: linear-gradient(145deg, #1d4ed8 0%, #2673dd 100%);
}
.mall-flip-back--teal {
background-image: linear-gradient(145deg, #00897b 0%, #00bfa5 100%);
}
.mall-back-tag {
font-size: 1.05rem;
font-weight: 700;
letter-spacing: 0.06rem;
background-color: rgba(255, 255, 255, 0.2);
padding: 0.3rem 1rem;
border-radius: 2rem;
}
.mall-back-deal {
font-size: 2.6rem;
font-weight: 800;
line-height: 3rem;
}
.mall-back-cond {
font-size: 1.25rem;
line-height: 1.8rem;
opacity: 0.92;
}
.mall-back-code {
background-color: rgba(0, 0, 0, 0.2);
border: 1px dashed rgba(255, 255, 255, 0.65);
padding: 0.45rem 1.4rem;
border-radius: 4px;
font-size: 1.25rem;
}
.mall-back-btn {
margin-top: 0.4rem;
height: 3.6rem;
padding: 0 2rem;
background-color: #ffffff;
color: #d0011b;
font-size: 1.35rem;
font-weight: 600;
border-radius: 2rem;
gap: 0.6rem;
transition: transform 0.15s ease;
}
.mall-back-btn:hover {
transform: scale(1.05);
}
Bước 3: Bổ sung quy tắc Responsive cho Lưới Shopee Mall trong ./assets/css/responsive.css
Trên màn hình Tablet (<= 1023px) ta hạ xuống 2 cột, và trên Điện thoại (<= 739px) xếp gọn 1 cột để mặt sau của thẻ luôn rộng rãi, dễ đọc:
CSS
/* Bổ sung vào cuối khối @media (max-width: 1023px) trong ./assets/css/responsive.css */
.mall-flip-grid {
grid-template-columns: repeat(2, 1fr);
padding: 1.6rem;
}
.mall-brand-heading {
border-right: none;
padding-right: 0;
}
/* Bổ sung vào cuối khối @media (max-width: 739px) trong ./assets/css/responsive.css */
.mall-flip-grid {
grid-template-columns: 1fr;
}
3. Giải mã dòng code: 3 Điểm sáng Kỹ thuật trong Bài 74
-
Bộ ba
perspective: 100rem+transform-style: preserve-3d+backface-visibility: hidden:- Đây là công thức chuẩn mực cho mọi hiệu ứng lật thẻ 3D trên web.
cubic-bezier(0.4, 0, 0.2, 1)tạo nhịp xoay có gia tốc tự nhiên ở giữa và giảm tốc êm ái khi úp mặt sau vào đúng vị trí.
- Đây là công thức chuẩn mực cho mọi hiệu ứng lật thẻ 3D trên web.
-
Hỗ trợ cả Mobile & Bàn phím nhờ
tabindex="0"+:focus-within:- Trên điện thoại không có thao tác rê chuột
:hover. Bằng cách gắntabindex="0"lên<article class="mall-flip-card">và thêm.mall-flip-card:focus-within .mall-flip-inner, người dùng di động chỉ cần chạm vào thẻ là thẻ lập tức lật 3D để bấm vào nút "Vào Gian Hàng"!
- Trên điện thoại không có thao tác rê chuột
-
Viên thuốc Logo
.mall-logo-pillvắt ngang ranh giới ảnh và chữ:- Đặt
bottom: -1.6remtrên.mall-front-visualkết hợppadding-top: 2.4remtrên.mall-front-infotạo hiệu ứng logo thương hiệu nổi bồng bềnh nối liền phần ảnh sản phẩm với tên gian hàng phía dưới.
- Đặt
4. Bài tập trải nghiệm thực tế & Hẹn gặp ở Bài 75!
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!
-
Cuộn tới khu vực SHOPEE MALL — CỔNG THƯƠNG HIỆU CHÍNH HÃNG (Bài 74):
-
Đưa chuột lướt qua lần lượt 4 thẻ thương hiệu AULA, SONY, LG, ANKER: Từng thẻ sẽ xoay lật 180° trong không gian 3D cực kỳ mượt mà, hé lộ mã giảm giá độc quyền của từng hãng ở mặt sau!
-
Thử bật Dark Mode (Bài 55) trên Header để kiểm tra độ tương phản sắc nét của cả mặt trước lẫn mặt sau thẻ Mall.
-
Ở Bài 75 (Cột mốc 75/100 — 3/4 chặng đường!), chúng ta sẽ tiếp tục xây dựng một cửa sổ thu thập ý kiến khách hàng cực kỳ tinh tế: Cửa Sổ "Khảo Sát Mức Độ Hài Lòng" (NPS Rating 1–10 & Emoji Feedback Modal) hoàn toàn bằng CSS thuần!
All rights reserved