0

[Series 100 Bài Học HTML/CSS Thực Chiến - Bài 94]: Xây Dựng Màn Hình "Trung Tâm Bảo Mật & Xác Thực 2 Lớp (2FA Security)" Với Danh Sách Thiết Bị Đang Đăng Nhập & Đăng Xuất Từ Xa Bằng CSS Thuần

Chào mừng anh em đã bước sang Bài 94 — chỉ còn 6 bài nữa là chạm đích 100/100 trong chuỗi 100 Bài Học Làm Chủ HTML/CSS Qua Dự Án Clone Shopee!

Ở Bài 93, chúng ta đã hoàn thành Trang Trạng Thái Hệ Thống Shopee (System Status & Uptime UI) với biểu đồ thanh Uptime 30 ngày và Tooltip đọc trực tiếp từ attr(data-tip). Hôm nay, chúng ta sẽ xây dựng lá chắn bảo vệ tối quan trọng cho tài khoản và Ví ShopeePay của người dùng: Màn Hình "Trung Tâm Bảo Mật & Xác Thực 2 Lớp (2FA Security)"!

Một trang bảo mật tài khoản chuẩn mực không chỉ dừng lại ở các nút đổi mật khẩu khô khan, mà phải giúp người dùng đánh giá ngay mức độ an toàn và ngắt kết nối thiết bị lạ chỉ trong 1 cú click. Trong Bài 94, chúng ta sẽ chinh phục 4 kỹ thuật CSS thuần thực chiến:

  1. Vòng Tròn Điểm Bảo Mật Tài Khoản (Security Score Ring bằng conic-gradient()): Vẽ biểu đồ vòng tròn 95 / 100 — Rất An Toàn màu Xanh Ngọc (#00bfa5) hoàn toàn bằng CSS thuần mà không cần SVG hay Chart.js!

  2. Công Tắc Xác Thực 2 Lớp (2FA Master Switch) & Bộ Chọn Phương Thức Bằng :has(): Gạt bật/tắt 2FA sẽ tự động mở khóa hoặc khóa mờ 3 phương thức bảo vệ (Ứng dụng Authenticator, SMS OTP, Passkey / Vân tay), kèm ngăn kéo <details> chứa 6 ô nhập mã OTP chuyên nghiệp.

  3. Danh Sách Thiết Bị Đang Đăng Nhập & Nút "Đăng Xuất Từ Xa" Tức Thì (:has() + Checkbox Hack): Phân tách rõ Thiết bị hiện tại (chấm xanh đang hoạt động) với các thiết bị khác. Khi bấm nút "Đăng xuất" trên một thiết bị khác, dòng thiết bị đó lập tức mờ xuống, gạch ngang tên thiết bị và đổi nhãn thành "✓ Đã đăng xuất từ xa" hoàn toàn không cần JavaScript!

  4. Tương Thích 100% Với Dark Mode (Bài 55) & Responsive Đa Thiết Bị.

1. Giải phẫu Màn Hình "Trung Tâm Bảo Mật & Xác Thực 2 Lớp (2FA)"

Hãy quan sát giao diện thực tế của khu vực Thiết Lập Bảo Mật 2 Lớp trên Shopee — nơi người dùng kiểm soát mã xác thực OTP, mật khẩu đăng nhập và quản lý các thiết bị tin cậy:

image.png

Toàn bộ khu vực Trung Tâm Bảo Mật (.security-center-section) được tổ chức thành 2 cột cân đối (1.15fr Xác thực 2 lớp 2FA & Nhập mã OTP bên trái | 1fr Danh sách Thiết bị Đang Đăng Nhập & Đăng xuất từ xa bên phải):

Plaintext

+-----------------------------------------------------------------------------------+
|  ( 95/100 )  TRUNG TÂM BẢO MẬT TÀI KHOẢN                  [ 🛡️ Rất An Toàn ]      | <-- 1. Header + Vòng tròn điểm
|  conic-ring  Tài khoản minh_hieu_dev đang được bảo vệ bởi Xác thực 2 lớp (2FA)    |     (vẽ bằng conic-gradient)
+-----------------------------------------------------------------------------------+
|  CỘT TRÁI: XÁC THỰC 2 LỚP (2FA)            | CỘT PHẢI: THIẾT BỊ ĐANG ĐĂNG NHẬP    | <-- 2. Bố cục 2 cột
|  [ 🛡️ Xác Thực 2 Lớp (2FA)      (===⚪) ]  |  💻 Chrome on Windows · TP.HCM       |
|  Chọn phương thức ưu tiên (Radio):         |     ● Thiết bị hiện tại              |
|  (●) Ứng dụng Authenticator (Khuyên dùng)  |  ----------------------------------  |
|  ( ) Tin nhắn SMS OTP (0941 *** 073)       |  📱 iPhone 15 Pro · TP.HCM           |
|  ( ) Passkey / Sinh trắc học FaceID        |     Hoạt động 12p trước [Đăng xuất]  | <-- Bấm -> Mờ & ✓ Đã đăng xuất!
|                                            |  ----------------------------------  |
|  [ 🔑 Kiểm Tra Mã OTP 6 Số ▾ ] (<details>) |  💻 Safari on MacBook · Hà Nội       |
|  [ 8 ] [ 4 ] [ 2 ] [ 9 ] [ 1 ] [ 6 ]       |     Hoạt động 2 ngày  [Đăng xuất]    |
+-----------------------------------------------------------------------------------+
Kỹ thuật CSS trong Bài 94 Khai báo cốt lõi Tác dụng thực chiến
Vòng tròn Điểm Bảo Mật 95% background: conic-gradient(#00bfa5 0% 95%, var(--border-subtle) 95% 100%); + lõi tròn trắng ở tâm Vẽ biểu đồ Donut sắc nét chuẩn màn hình Retina chỉ với 3 dòng CSS, không cần thư viện đồ thị.
Đăng xuất thiết bị từ xa bằng :has() .sec-device-item:has(.sec-logout-input:checked) { opacity: 0.5; } Bấm "Đăng xuất" trên bất kỳ thiết bị nào sẽ lập tức gạch ngang tên thiết bị, đổi nút thành "✓ Đã đăng xuất" mà không ảnh hưởng các thiết bị khác!
Khóa nhóm phương thức 2FA khi gạt tắt .sec-2fa-card:has(#sec-2fa-master:not(:checked)) .sec-methods-list {
opacity: 0.45;
pointer-events: none;
}
Gạt tắt công tắc 2FA sẽ tự động vô hiệu hóa cả 3 lựa chọn bên dưới và đổi nhãn trạng thái sang màu Đỏ cảnh báo.

2. Thực hành: Code Màn Hình "Trung Tâm Bảo Mật & Xác Thực 2 Lớp (2FA)" (index.html & main.css)

Bước 1: Bổ sung HTML Khối Trung Tâm Bảo Mật (.security-center-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 Trạng Thái Hệ Thống Shopee của Bài 93) và chèn toàn bộ cấu trúc Bài 94: Trung Tâm Bảo Mật & Xác Thực 2 Lớp (2FA Security) dưới đây:

HTML

        <!-- ================================================================= -->
        <!-- BÀI 94: TRUNG TÂM BẢO MẬT & XÁC THỰC 2 LỚP (2FA SECURITY)         -->
        <!-- ================================================================= -->
        <section class="security-center-section">
            
            <!-- 1. HEADER & VÒNG TRÒN ĐIỂM BẢO MẬT (CONIC-GRADIENT RING) -->
            <header class="sec-header">
                <div class="sec-header__left">
                    <!-- Vòng tròn điểm bảo mật 95/100 vẽ bằng CSS conic-gradient -->
                    <div class="sec-score-ring" role="img" aria-label="Điểm bảo mật tài khoản 95 trên 100">
                        <div class="sec-score-inner">
                            <strong>95</strong>
                            <span>/100</span>
                        </div>
                    </div>

                    <div>
                        <div class="sec-title-row">
                            <h2 class="sec-header__title">Trung Tâm Bảo Mật &amp; Xác Thực 2 Lớp (2FA)</h2>
                            <span class="sec-level-badge">
                                <i class="fa-solid fa-shield-check"></i> Rất An Toàn
                            </span>
                        </div>
                        <p class="sec-header__sub">
                            Tài khoản <strong>minh_hieu_dev</strong> đã xác minh Email, SĐT và kích hoạt Xác thực 2 lớp cho Ví ShopeePay.
                        </p>
                    </div>
                </div>

                <a href="#" class="btn order-btn--secondary sec-pass-btn">
                    <i class="fa-solid fa-key"></i> Đổi Mật Khẩu
                </a>
            </header>

            <!-- 2. BỐ CỤC 2 CỘT: CẤU HÌNH 2FA (TRÁI) | THIẾT BỊ ĐANG ĐĂNG NHẬP (PHẢI) -->
            <div class="sec-layout">
                
                <!-- ========================================================= -->
                <!-- CỘT TRÁI: XÁC THỰC 2 LỚP (2FA) & Ô NHẬP MÃ OTP 6 SỐ       -->
                <!-- ========================================================= -->
                <div class="sec-2fa-card">
                    
                    <!-- Công tắc tổng Bật / Tắt Xác Thực 2 Lớp -->
                    <label class="sec-2fa-master-row" for="sec-2fa-master">
                        <div class="sec-2fa-master__info">
                            <span class="sec-2fa-icon"><i class="fa-solid fa-fingerprint"></i></span>
                            <div>
                                <h3>Xác Thực 2 Lớp (2FA)</h3>
                                <span class="sec-2fa-status sec-2fa--on">● Đang bảo vệ mọi lần đăng nhập thiết bị mới</span>
                                <span class="sec-2fa-status sec-2fa--off">● Đã tắt — Tài khoản có nguy cơ mất an toàn!</span>
                            </div>
                        </div>
                        <span class="priv-switch">
                            <input type="checkbox" id="sec-2fa-master" class="priv-switch__input" checked>
                            <span class="priv-switch__slider"></span>
                        </span>
                    </label>

                    <!-- Danh sách 3 phương thức xác thực (Tự mờ & khóa khi tắt 2FA!) -->
                    <div class="sec-methods-list" role="radiogroup" aria-label="Chọn phương thức xác thực 2 lớp">
                        <span class="sec-block-label">Phương thức nhận mã xác thực ưu tiên:</span>

                        <label class="sec-method-item">
                            <input type="radio" name="sec-2fa-method" class="sec-ctrl-input" checked>
                            <span class="sec-method-card">
                                <span class="sec-method-icon sec-m-icon--app"><i class="fa-solid fa-mobile-screen"></i></span>
                                <div class="sec-method-info">
                                    <strong>Ứng dụng Authenticator <span class="sec-rec-tag">Khuyên dùng</span></strong>
                                    <span>Tạo mã 6 số ngoại tuyến qua Google / Microsoft Authenticator</span>
                                </div>
                                <span class="sec-radio-dot"></span>
                            </span>
                        </label>

                        <label class="sec-method-item">
                            <input type="radio" name="sec-2fa-method" class="sec-ctrl-input">
                            <span class="sec-method-card">
                                <span class="sec-method-icon sec-m-icon--sms"><i class="fa-solid fa-comment-sms"></i></span>
                                <div class="sec-method-info">
                                    <strong>Tin nhắn SMS OTP</strong>
                                    <span>Gửi mã xác minh về số điện thoại 0941 *** 073</span>
                                </div>
                                <span class="sec-radio-dot"></span>
                            </span>
                        </label>

                        <label class="sec-method-item">
                            <input type="radio" name="sec-2fa-method" class="sec-ctrl-input">
                            <span class="sec-method-card">
                                <span class="sec-method-icon sec-m-icon--passkey"><i class="fa-solid fa-shield-halved"></i></span>
                                <div class="sec-method-info">
                                    <strong>Passkey / Sinh trắc học (FaceID, Vân tay)</strong>
                                    <span>Đăng nhập không cần mật khẩu, chống giả mạo Phishing 100%</span>
                                </div>
                                <span class="sec-radio-dot"></span>
                            </span>
                        </label>
                    </div>

                    <!-- Ngăn kéo Kiểm tra Mã OTP 6 Số (<details>) -->
                    <details class="sec-otp-drawer" open>
                        <summary class="sec-otp-trigger">
                            <i class="fa-solid fa-hashtag"></i> Kiểm thử xác minh mã OTP 6 chữ số
                        </summary>

                        <form class="sec-otp-form" onsubmit="return false;">
                            <p class="sec-otp-hint">Nhập 6 chữ số hiển thị trên ứng dụng Authenticator của bạn:</p>
                            <div class="sec-otp-boxes">
                                <input type="text" maxlength="1" class="sec-otp-digit" value="8" aria-label="Số thứ 1">
                                <input type="text" maxlength="1" class="sec-otp-digit" value="4" aria-label="Số thứ 2">
                                <input type="text" maxlength="1" class="sec-otp-digit" value="2" aria-label="Số thứ 3">
                                <input type="text" maxlength="1" class="sec-otp-digit" value="9" aria-label="Số thứ 4">
                                <input type="text" maxlength="1" class="sec-otp-digit" value="1" aria-label="Số thứ 5">
                                <input type="text" maxlength="1" class="sec-otp-digit" value="6" aria-label="Số thứ 6">
                            </div>
                            <button type="submit" class="btn btn--primary sec-otp-verify-btn">
                                <i class="fa-solid fa-circle-check"></i> Xác Minh Mã OTP
                            </button>
                        </form>
                    </details>

                </div>

                <!-- ========================================================= -->
                <!-- CỘT PHẢI: DANH SÁCH THIẾT BỊ ĐANG ĐĂNG NHẬP & ĐĂNG XUẤT   -->
                <!-- ========================================================= -->
                <aside class="sec-devices-card">
                    <div class="sec-devices__head">
                        <div>
                            <h3>Thiết Bị Đang Đăng Nhập (3)</h3>
                            <span>Bấm <strong>Đăng xuất</strong> ngay nếu phát hiện thiết bị lạ</span>
                        </div>
                        <span class="sec-active-pill"><i class="fa-solid fa-circle"></i> 3 phiên</span>
                    </div>

                    <div class="sec-device-list">
                        
                        <!-- Thiết bị 1: Thiết bị hiện tại (Không cho đăng xuất nhầm) -->
                        <article class="sec-device-item sec-device--current">
                            <span class="sec-dev-icon"><i class="fa-solid fa-laptop"></i></span>
                            <div class="sec-dev-info">
                                <strong>Chrome trên Windows 11 <span class="sec-current-tag">Thiết bị này</span></strong>
                                <span class="sec-dev-meta">TP. Hồ Chí Minh, Việt Nam · IP: 113.161.***.42</span>
                                <span class="sec-dev-time sec-time--online">● Đang hoạt động ngay bây giờ</span>
                            </div>
                        </article>

                        <!-- Thiết bị 2: iPhone 15 Pro (Bấm Đăng xuất -> Tự mờ & đổi trạng thái!) -->
                        <article class="sec-device-item">
                            <input type="checkbox" id="sec-logout-dev2" class="sec-ctrl-input sec-logout-input">

                            <span class="sec-dev-icon"><i class="fa-solid fa-mobile-screen-button"></i></span>
                            <div class="sec-dev-info">
                                <strong class="sec-dev-name">Shopee App · iPhone 15 Pro</strong>
                                <span class="sec-dev-meta">TP. Hồ Chí Minh, Việt Nam · IP: 14.169.***.18</span>
                                <span class="sec-dev-time sec-time-before">Hoạt động 12 phút trước</span>
                                <span class="sec-dev-time sec-time-after"><i class="fa-solid fa-circle-check"></i> Đã đăng xuất từ xa</span>
                            </div>

                            <label for="sec-logout-dev2" class="btn order-btn--secondary sec-logout-btn">
                                <span class="sec-lo-before">Đăng xuất</span>
                                <span class="sec-lo-after">Đã thoát</span>
                            </label>
                        </article>

                        <!-- Thiết bị 3: MacBook Air tại Hà Nội (Thiết bị lạ -> Đăng xuất từ xa!) -->
                        <article class="sec-device-item">
                            <input type="checkbox" id="sec-logout-dev3" class="sec-ctrl-input sec-logout-input">

                            <span class="sec-dev-icon"><i class="fa-solid fa-desktop"></i></span>
                            <div class="sec-dev-info">
                                <strong class="sec-dev-name">Safari trên macOS (MacBook Air)</strong>
                                <span class="sec-dev-meta">Hà Nội, Việt Nam · IP: 118.70.***.91</span>
                                <span class="sec-dev-time sec-time-before">Hoạt động 2 ngày trước</span>
                                <span class="sec-dev-time sec-time-after"><i class="fa-solid fa-circle-check"></i> Đã đăng xuất từ xa</span>
                            </div>

                            <label for="sec-logout-dev3" class="btn order-btn--secondary sec-logout-btn">
                                <span class="sec-lo-before">Đăng xuất</span>
                                <span class="sec-lo-after">Đã thoát</span>
                            </label>
                        </article>

                    </div>

                    <!-- Mẹo bảo mật tài khoản -->
                    <div class="sec-tip-box">
                        <i class="fa-solid fa-lightbulb"></i>
                        <span><strong>Mẹo an toàn:</strong> Không bao giờ chia sẻ mã OTP 6 số cho bất kỳ ai, kể cả người tự xưng là nhân viên Shopee hay Shipper!</span>
                    </div>
                </aside>

            </div>

        </section>

Bước 2: Viết CSS cho 2FA Security Center & Đăng Xuất Từ Xa :has() 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 94 dưới đây:

CSS

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

/* --- BÀI 94: TRUNG TÂM BẢO MẬT & XÁC THỰC 2 LỚP (2FA SECURITY) --- */

.security-center-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;
}

.sec-ctrl-input {
    display: none;
}

/* 1. Header & Vòng Tròn Điểm Bảo Mật (conic-gradient) */
.sec-header {
    padding: 2.2rem 2.4rem;
    border-bottom: 1px solid var(--border-subtle, #eeeeee);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1.8rem;
}

.sec-header__left {
    display: flex;
    align-items: center;
    gap: 1.8rem;
}

/* BÍ THUẬT: VÒNG TRÒN ĐIỂM BẢO MẬT 95/100 BẰNG CONIC-GRADIENT */
.sec-score-ring {
    width: 6.4rem;
    height: 6.4rem;
    border-radius: 50%;
    background-image: conic-gradient(
        #00bfa5 0% 95%,
        var(--border-subtle, #e5e7eb) 95% 100%
    );
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.sec-score-inner {
    width: 5rem;
    height: 5rem;
    border-radius: 50%;
    background-color: var(--white-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    line-height: 1.4rem;
    font-variant-numeric: tabular-nums;
}

.sec-score-inner strong {
    font-size: 1.8rem;
    font-weight: 800;
    color: #00bfa5;
}

.sec-score-inner span {
    font-size: 1rem;
    color: var(--text-secondary);
}

.sec-title-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 0.4rem;
}

.sec-header__title {
    font-size: 1.85rem;
    font-weight: 600;
    color: var(--text-primary);
}

.sec-level-badge {
    font-size: 1.15rem;
    font-weight: 700;
    color: #00bfa5;
    background-color: rgba(0, 191, 165, 0.12);
    padding: 0.25rem 1rem;
    border-radius: 2rem;
}

.sec-header__sub {
    font-size: 1.3rem;
    color: var(--text-secondary);
}

.sec-pass-btn {
    height: 3.8rem;
    padding: 0 1.6rem;
    font-size: 1.35rem;
    gap: 0.7rem;
}

/* ================================================================= */
/* 2. BỐ CỤC 2 CỘT: XÁC THỰC 2 LỚP (2FA) & THIẾT BỊ ĐANG ĐĂNG NHẬP   */
/* ================================================================= */
.sec-layout {
    padding: 2.4rem;
    display: grid;
    grid-template-columns: 1.15fr 1fr;
    gap: 2.4rem;
    align-items: start;
}

.sec-2fa-card,
.sec-devices-card {
    border: 1px solid var(--border-subtle, #e8e8e8);
    border-radius: 8px;
    padding: 2rem;
    background-color: var(--bg-elevated, #fafafa);
}

/* Hàng Công tắc tổng Bật / Tắt 2FA */
.sec-2fa-master-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.4rem;
    padding-bottom: 1.8rem;
    margin-bottom: 1.8rem;
    border-bottom: 1px solid var(--border-subtle, #e5e7eb);
    cursor: pointer;
    user-select: none;
}

.sec-2fa-master__info {
    display: flex;
    align-items: center;
    gap: 1.2rem;
}

.sec-2fa-icon {
    width: 4.2rem;
    height: 4.2rem;
    border-radius: 1rem;
    background-color: rgba(0, 191, 165, 0.12);
    color: #00bfa5;
    font-size: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.sec-2fa-master__info h3 {
    font-size: 1.6rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.sec-2fa-status {
    font-size: 1.2rem;
    font-weight: 500;
}

.sec-2fa--on  { color: #00bfa5; }
.sec-2fa--off { color: #ff424f; display: none; }

/* BÍ THUẬT :HAS() — KHI TẮT 2FA -> KHÓA NHÓM PHƯƠNG THỨC & BẬT CẢNH BÁO ĐỎ! */
.sec-2fa-card:has(#sec-2fa-master:not(:checked)) .sec-2fa--on  { display: none; }
.sec-2fa-card:has(#sec-2fa-master:not(:checked)) .sec-2fa--off { display: inline; }
.sec-2fa-card:has(#sec-2fa-master:not(:checked)) .sec-methods-list,
.sec-2fa-card:has(#sec-2fa-master:not(:checked)) .sec-otp-drawer {
    opacity: 0.45;
    pointer-events: none;
}

/* Danh sách 3 phương thức 2FA */
.sec-methods-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1.8rem;
    transition: opacity 0.2s ease;
}

.sec-block-label {
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.2rem;
}

.sec-method-item {
    cursor: pointer;
    user-select: none;
}

.sec-method-card {
    display: flex;
    align-items: center;
    gap: 1.2rem;
    padding: 1.2rem 1.4rem;
    border: 1.5px solid var(--border-subtle, #e0e0e0);
    border-radius: 6px;
    background-color: var(--white-color);
    transition: all 0.15s ease;
}

.sec-method-card:hover {
    border-color: var(--shopee-primary);
}

.sec-method-icon {
    width: 3.6rem;
    height: 3.6rem;
    border-radius: 8px;
    font-size: 1.6rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.sec-m-icon--app     { background-color: rgba(37, 99, 235, 0.12); color: #2563eb; }
.sec-m-icon--sms     { background-color: rgba(0, 191, 165, 0.12); color: #00bfa5; }
.sec-m-icon--passkey { background-color: rgba(124, 58, 237, 0.12); color: #7c3aed; }

.sec-method-info {
    flex: 1;
    min-width: 0;
}

.sec-method-info strong {
    display: block;
    font-size: 1.35rem;
    color: var(--text-primary);
    margin-bottom: 0.2rem;
}

.sec-rec-tag {
    font-size: 1rem;
    font-weight: 700;
    color: #00bfa5;
    background-color: rgba(0, 191, 165, 0.12);
    padding: 0.1rem 0.6rem;
    border-radius: 2rem;
    margin-left: 0.4rem;
}

.sec-method-info span {
    font-size: 1.2rem;
    color: var(--text-secondary);
}

.sec-radio-dot {
    width: 1.8rem;
    height: 1.8rem;
    border-radius: 50%;
    border: 2px solid #cbd5e1;
    flex-shrink: 0;
    position: relative;
}

.sec-method-item input:checked + .sec-method-card {
    border-color: var(--shopee-primary);
    background-color: var(--bg-soft-accent, #fffbf8);
}

.sec-method-item input:checked + .sec-method-card .sec-radio-dot {
    border-color: var(--shopee-primary);
}

.sec-method-item input:checked + .sec-method-card .sec-radio-dot::after {
    content: "";
    position: absolute;
    inset: 0.3rem;
    border-radius: 50%;
    background-color: var(--shopee-primary);
}

/* Ngăn kéo Ô nhập mã OTP 6 chữ số (<details>) */
.sec-otp-drawer {
    background-color: var(--white-color);
    border: 1px dashed var(--border-subtle, #dcdcdc);
    border-radius: 6px;
    padding: 1.2rem 1.6rem;
    transition: opacity 0.2s ease;
}

.sec-otp-trigger {
    font-size: 1.35rem;
    font-weight: 600;
    color: var(--shopee-primary);
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.sec-otp-trigger::-webkit-details-marker {
    display: none;
}

.sec-otp-form {
    margin-top: 1.2rem;
    padding-top: 1.2rem;
    border-top: 1px solid var(--border-subtle, #f0f0f0);
}

.sec-otp-hint {
    font-size: 1.2rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.sec-otp-boxes {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 0.8rem;
    margin-bottom: 1.4rem;
}

.sec-otp-digit {
    width: 100%;
    height: 4.4rem;
    text-align: center;
    font-family: monospace;
    font-size: 2rem;
    font-weight: 800;
    color: var(--text-primary);
    background-color: var(--bg-elevated, #fafafa);
    border: 1.5px solid var(--border-subtle, #dcdcdc);
    border-radius: 6px;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.sec-otp-digit:focus {
    border-color: var(--shopee-primary);
    background-color: var(--white-color);
    box-shadow: 0 0 0 0.3rem rgba(238, 77, 45, 0.12);
}

.sec-otp-verify-btn {
    width: 100%;
    height: 3.8rem;
    font-size: 1.35rem;
    font-weight: 600;
    gap: 0.6rem;
}

/* ================================================================= */
/* 3. CỘT PHẢI: DANH SÁCH THIẾT BỊ ĐANG ĐĂNG NHẬP & ĐĂNG XUẤT TỪ XA */
/* ================================================================= */
.sec-devices__head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding-bottom: 1.4rem;
    margin-bottom: 1.4rem;
    border-bottom: 1px solid var(--border-subtle, #e5e7eb);
}

.sec-devices__head h3 {
    font-size: 1.55rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.sec-devices__head span {
    font-size: 1.2rem;
    color: var(--text-secondary);
}

.sec-active-pill {
    font-size: 1.15rem;
    font-weight: 600;
    color: #00bfa5;
    background-color: rgba(0, 191, 165, 0.12);
    padding: 0.3rem 1rem;
    border-radius: 2rem;
    white-space: nowrap;
}

.sec-active-pill i {
    font-size: 0.7rem;
    vertical-align: middle;
    margin-right: 0.3rem;
}

.sec-device-list {
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
    margin-bottom: 1.6rem;
}

.sec-device-item {
    display: flex;
    align-items: center;
    gap: 1.2rem;
    padding: 1.4rem;
    border: 1px solid var(--border-subtle, #e5e7eb);
    border-radius: 6px;
    background-color: var(--white-color);
    transition: opacity 0.25s ease, border-color 0.2s ease;
}

.sec-device--current {
    border-color: rgba(0, 191, 165, 0.5);
    background-color: rgba(0, 191, 165, 0.04);
}

.sec-dev-icon {
    width: 4rem;
    height: 4rem;
    border-radius: 8px;
    background-color: var(--bg-elevated, #f3f4f6);
    color: var(--text-primary);
    font-size: 1.7rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.sec-dev-info {
    flex: 1;
    min-width: 0;
}

.sec-dev-info strong {
    display: block;
    font-size: 1.35rem;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.sec-current-tag {
    font-size: 1rem;
    font-weight: 700;
    color: #ffffff;
    background-color: #00bfa5;
    padding: 0.15rem 0.7rem;
    border-radius: 2rem;
    margin-left: 0.5rem;
}

.sec-dev-meta {
    display: block;
    font-size: 1.15rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.sec-dev-time {
    font-size: 1.15rem;
    color: var(--text-secondary);
}

.sec-time--online {
    color: #00bfa5;
    font-weight: 600;
}

.sec-logout-btn {
    height: 3.2rem;
    padding: 0 1.2rem;
    font-size: 1.2rem;
    font-weight: 600;
    cursor: pointer;
    user-select: none;
    flex-shrink: 0;
}

.sec-time-after,
.sec-lo-after {
    display: none;
}

/* BÍ THUẬT :HAS() — ĐĂNG XUẤT THIẾT BỊ TỪ XA TỨC THÌ KHÔNG CẦN JS! */
.sec-device-item:has(.sec-logout-input:checked) {
    opacity: 0.52;
    border-style: dashed;
}

.sec-device-item:has(.sec-logout-input:checked) .sec-dev-name {
    text-decoration: line-through;
}

.sec-device-item:has(.sec-logout-input:checked) .sec-time-before,
.sec-device-item:has(.sec-logout-input:checked) .sec-lo-before {
    display: none;
}

.sec-device-item:has(.sec-logout-input:checked) .sec-time-after {
    display: inline;
    color: #00bfa5;
    font-weight: 600;
}

.sec-device-item:has(.sec-logout-input:checked) .sec-lo-after {
    display: inline;
}

.sec-tip-box {
    display: flex;
    align-items: flex-start;
    gap: 0.9rem;
    padding: 1.2rem 1.4rem;
    background-color: rgba(245, 158, 11, 0.08);
    border-left: 3px solid #f59e0b;
    border-radius: 4px;
    font-size: 1.2rem;
    line-height: 1.8rem;
    color: var(--text-secondary);
}

.sec-tip-box i {
    color: #d97706;
    margin-top: 0.2rem;
}

Bước 3: Bổ sung quy tắc Responsive cho 2FA Security Center trong ./assets/css/responsive.css

Trên màn hình Tablet (dưới 1023px) và Điện thoại (dưới 739px), chúng ta chuyển bố cục 2 cột sang xếp chồng dọc và xếp gọn nút Đăng xuất trên màn hình nhỏ:

CSS

/* Bổ sung vào cuối khối @media (max-width: 1023px) trong ./assets/css/responsive.css */
    .sec-layout {
        grid-template-columns: 1fr;
    }

/* Bổ sung vào cuối khối @media (max-width: 739px) trong ./assets/css/responsive.css */
    .sec-header,
    .sec-layout {
        padding: 1.6rem;
    }

    .sec-2fa-card,
    .sec-devices-card {
        padding: 1.4rem;
    }

    .sec-device-item {
        flex-wrap: wrap;
    }

    .sec-logout-btn {
        width: 100%;
    }

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

  1. Vòng tròn Điểm Bảo Mật 95/100 không cần SVG (.sec-score-ring):

    • Kết hợp conic-gradient(#00bfa5 0% 95%, var(--border-subtle) 95% 100%) ở vòng ngoài và một vòng tròn con .sec-score-inner nền var(--white-color) ở giữa giúp vẽ biểu đồ tròn sạch sẽ, tự động đổi màu nền lõi khi bật Dark Mode.
  2. Đăng xuất từng thiết bị độc lập bằng .sec-device-item:has(.sec-logout-input:checked):

    • Mỗi thiết bị chứa một checkbox ẩn riêng. Khi bấm "Đăng xuất", chỉ đúng thiết bị đó bị mờ đi (opacity: 0.52), chuyển viền sang nét đứt, gạch ngang tên thiết bị và hiện dòng xanh "✓ Đã đăng xuất từ xa".
  3. 6 ô nhập mã OTP chuẩn UX ngân hàng (.sec-otp-boxes):

    • Dùng lưới repeat(6, 1fr) với font monospace, cỡ chữ 2rem căn giữa và hiệu ứng viền sáng cam khi :focus giúp người dùng dễ dàng kiểm tra từng chữ số mã xác thực.

4. Bài tập trải nghiệm thực tế & Chào đón Cột mốc Bài 95!

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 TRUNG TÂM BẢO MẬT & XÁC THỰC 2 LỚP (Bài 94):

    • Thử bấm "Đăng xuất" ở thiết bị Safari trên macOS (Hà Nội) bên cột phải: Thiết bị lập tức mờ xuống, gạch ngang tên và đổi sang trạng thái "✓ Đã đăng xuất từ xa"!

    • Thử gạt tắt công tắc tổng Xác Thực 2 Lớp (2FA) ở cột trái: Dòng trạng thái lập tức chuyển sang màu Đỏ cảnh báo và khóa mờ cả 3 phương thức xác thực bên dưới!

🏆 CHUẨN BỊ CHÀO ĐÓN BÀI 95 — CỘT MỐC 95/100 (CHỈ CÒN 5 BÀI CUỐI CÙNG)! Ở Bài 95, chúng ta sẽ xây dựng Trang "Trung Tâm Giải Quyết Khiếu Nại & Hoàn Tiền Shopee" với sơ đồ quy trình 4 bước và biểu mẫu gửi bằng chứng (ảnh/video mở hộp) bằng CSS thuần!


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í