Thứ Tư, 8 tháng 7, 2026

Hiệu ứng Popup - Detail Product

 



## HTML

<!DOCTYPE html>
<html lang="vi">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Slide Popup Lightbox</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>

<!-- Danh sách các hình ảnh hiển thị trên trang -->
<div class="image-gallery">
    <div class="gallery-item">
        <img src="1.jpg" alt="máy giặt bong bóng" class="popup-trigger"
             data-title-vi="máy giặt bong bóng" 
             data-date="May 19,2021" 
             data-title-en="Bubble Washing Machine" 
             data-desc="The bubbling cleaning machine is designed for materials with high shape requirements. It is...">
        <p>máy giặt bong bóng</p>
    </div>
    <div class="gallery-item">
        <img src="2.jpg" alt="máy chiết rót nước sốt" class="popup-trigger"
             data-title-vi="máy chiết rót nước sốt" 
             data-date="June 10,2022" 
             data-title-en="Sauce Filling Machine" 
             data-desc="Description for sauce filling machine goes here...">
        <p>máy chiết rót nước sốt</p>
    </div>
    <!-- Thêm các hình ảnh khác tại đây -->
</div>

<!-- Cấu trúc MODAL POPUP (Giống như trong ảnh z7975352149535_20ea4773eb8dace4aa835ec268dc0eab.jpg) -->
<div id="lightboxModal" class="modal">
    <!-- Nút đóng góc trên bên phải bên ngoài hoặc sát mép -->
    <span class="close-btn">&times;</span>
    
    <div class="modal-content">
        <!-- Phần Header của Popup -->
        <div class="modal-header">
            <h3 id="modalTitleVi">máy giặt bong bóng</h3>
            <span id="modalDate">May 19,2021</span>
        </div>

        <!-- Phần Thân chứa Ảnh và Nút chuyển đổi -->
        <div class="modal-body">
            <button class="nav-btn prev-btn">&#10094;</button>
            <div class="image-container">
                <img id="modalImage" src="" alt="Popup Image">
            </div>
            <button class="nav-btn next-btn">&#10095;</button>
        </div>

        <!-- Phần Footer chứa Mô tả -->
        <div class="modal-footer">
            <h4 id="modalTitleEn">Bubble Washing Machine</h4>
            <div class="desc-scroll">
                <p id="modalDesc">The bubbling cleaning machine is designed for materials with high shape requirements. It is...</p>
            </div>
        </div>
    </div>
</div>

<script src="script.js"></script>

<style type="text/css">
    
    /* Gallery ngoài trang */
body {
    font-family: Arial, sans-serif;
    background-color: #f4f4f4;
    margin: 0;
    padding: 20px;
}
.image-gallery {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}
.gallery-item {
    background: #fff;
    padding: 10px;
    border: 1px solid #ddd;
    text-align: center;
    cursor: pointer;
    width: 200px;
}
.gallery-item img {
    width: 100%;
    height: auto;
}

/* MODAL BACKGROUND */
.modal {
    display: none; /* Ẩn mặc định */
    position: fixed;
    z-index: 9999;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.5); /* Nền tối mờ phía sau */
    justify-content: center;
    align-items: center;
}

/* NÚT ĐÓNG (X) */
.close-btn {
    position: absolute;
    top: 20px;
    right: 30px;
    color: #fff;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
    background: rgba(0,0,0,0.3);
    width: 45px;
    height: 45px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
}
.close-btn:hover {
    background: rgba(0,0,0,0.6);
}

/* KHUNG POPUP CHÍNH */
.modal-content {
    background-color: #fff;
    width: 90%;
    max-width: 800px;
    border-radius: 4px;
    display: flex;
    flex-direction: column;
    position: relative;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

/* HEADER POPUP */
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 25px;
    border-bottom: 1px solid #eee;
}
.modal-header h3 {
    margin: 0;
    font-size: 16px;
    color: #333;
    font-weight: bold;
}
.modal-header span {
    font-size: 13px;
    color: #888;
}

/* THÂN POPUP CHỨA ẢNH VÀ DI CHUYỂN */
.modal-body {
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: relative;
    padding: 10px 0;
    background: #fff;
}
.image-container {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 400px; /* Chiều cao cố định cho vùng chứa ảnh */
}
.image-container img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* NÚT NEXT / PREV TRÁI PHẢI */
.nav-btn {
    background: rgba(0, 0, 0, 0.4);
    color: white;
    border: none;
    padding: 15px 12px;
    cursor: pointer;
    font-size: 20px;
    position: absolute;
    z-index: 10;
    transition: 0.2s;
}
.nav-btn:hover {
    background: rgba(0, 0, 0, 0.7);
}
.prev-btn { left: 0; border-radius: 0 4px 4px 0; }
.next-btn { right: 0; border-radius: 4px 0 0 4px; }

/* FOOTER POPUP CHỨA MÔ TẢ */
.modal-footer {
    padding: 20px 25px;
    border-top: 1px solid #eee;
    background: #fff;
}
.modal-footer h4 {
    margin: 0 0 10px 0;
    font-size: 16px;
    color: #444;
}


/* Tạo thanh cuộn cho nội dung dài giống hình ảnh mẫu */
.desc-scroll {
    max-height: 80px;
    overflow-y: auto;
    padding-right: 10px;
}
.desc-scroll p {
    margin: 0;
    font-size: 13px;
    color: #666;
    line-height: 1.5;
}
/* Tùy biến thanh cuộn đẹp hơn */
.desc-scroll::-webkit-scrollbar {
    width: 6px;
}
.desc-scroll::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 4px;
}
</style>

<script type="text/javascript">
    document.addEventListener("DOMContentLoaded", function () {
    const modal = document.getElementById("lightboxModal");
    const triggers = document.querySelectorAll(".popup-trigger");
    const closeBtn = document.querySelector(".close-btn");
    
    const modalImg = document.getElementById("modalImage");
    const modalTitleVi = document.getElementById("modalTitleVi");
    const modalDate = document.getElementById("modalDate");
    const modalTitleEn = document.getElementById("modalTitleEn");
    const modalDesc = document.getElementById("modalDesc");
    
    const prevBtn = document.querySelector(".prev-btn");
    const nextBtn = document.querySelector(".next-btn");

    let currentIndex = 0;

    // Hàm cập nhật nội dung cho Modal dựa trên Index của ảnh
    function updateModal(index) {
        const targetImg = triggers[index];
        
        modalImg.src = targetImg.src;
        modalTitleVi.textContent = targetImg.getAttribute("data-title-vi");
        modalDate.textContent = targetImg.getAttribute("data-date");
        modalTitleEn.textContent = targetImg.getAttribute("data-title-en");
        modalDesc.textContent = targetImg.getAttribute("data-desc");
        
        currentIndex = index;
    }

    // Lắng nghe sự kiện click vào từng bức ảnh
    triggers.forEach((trigger, index) => {
        trigger.addEventListener("click", function () {
            modal.style.display = "flex";
            updateModal(index);
        });
    });

    // Nút quay lại (Trái)
    prevBtn.addEventListener("click", function (e) {
        e.stopPropagation(); // Tránh lỗi tắt modal ngoài ý muốn
        let newIndex = currentIndex - 1;
        if (newIndex < 0) {
            newIndex = triggers.length - 1; // Quay về ảnh cuối cùng nếu vượt quá đầu danh sách
        }
        updateModal(newIndex);
    });

    // Nút kế tiếp (Phải)
    nextBtn.addEventListener("click", function (e) {
        e.stopPropagation();
        let newIndex = currentIndex + 1;
        if (newIndex >= triggers.length) {
            newIndex = 0; // Quay về ảnh đầu tiên nếu vượt quá cuối danh sách
        }
        updateModal(newIndex);
    });

    // Đóng modal khi bấm nút X
    closeBtn.addEventListener("click", function () {
        modal.style.display = "none";
    });

    // Đóng modal khi click ra vùng ngoài khung trắng
    modal.addEventListener("click", function (e) {
        if (e.target === modal) {
            modal.style.display = "none";
        }
    });
    
    // Hỗ trợ bấm nút điều hướng bằng bàn phím (Trái/Phải/Esc)
    document.addEventListener("keydown", function(e) {
        if (modal.style.display === "flex") {
            if (e.key === "ArrowLeft") {
                prevBtn.click();
            } else if (e.key === "ArrowRight") {
                nextBtn.click();
            } else if (e.key === "Escape") {
                modal.style.display = "none";
            }
        }
    });
});
</script>
</body>
</html>

## Demo

Link: https://vietb2b.com/nha-cung-cap-6-profile


Thứ Hai, 6 tháng 7, 2026

Hover Button css đẹp

 

## HTML

<div class="box-send-contact">

    <button class="button dark">Gửi thông tin</button>

</div>


## CSS

.button.dark {

    color: #fff;

    border-color: #0d2445;

}

.box-send-contact button {

    display: block;

    margin: 2rem auto 3rem auto;

}

.button:before {

    position: absolute;

    content: '';

    display: block;

    left: -2px;

    top: 0;

    right: -2px;

    bottom: 0;

    transform: scale(1, 1);

    transform-origin: left center;

    z-index: -1;

    background-color: #ffffff;

    transition: transform 0.45s cubic-bezier(0.785, 0.135, 0.15, 0.86);

}

.button.dark:before {

    background-color: #0d2445;

}

.button {

    font-weight: 600;

    position: relative;

    display: inline-block;

    padding: 1rem 2.8rem;

    line-height: normal;

    border: 1px solid #ffffff;

    border-radius: 50px;

    text-transform: uppercase;

    font-size: 1.2rem;

    text-align: center;

    letter-spacing: 1px;

    background-color: transparent;

    transition: color 0.45s cubic-bezier(0.785, 0.135, 0.15, 0.86), border 0.45s cubic-bezier(0.785, 0.135, 0.15, 0.86);

    z-index: 1;

    color: #0d2445;

    overflow: hidden;

}

.button:hover:before {

    transform-origin: right center;

    transform: scale(0, 1);

}

button:focus:not(:focus-visible) {

    outline: 0;

}

button.dark:hover {

    color: #0d2445;

}

Thứ Tư, 1 tháng 7, 2026

CSS clamp

 height: clamp(280px, 23vw, 450px);

có nghĩa là chiều cao sẽ tự co giãn theo kích thước màn hình nhưng luôn nằm trong khoảng từ 280px đến 450px.

Cú pháp của clamp() là:

clamp(MIN, PREFERRED, MAX)
  • 280px → Giá trị nhỏ nhất (không bao giờ thấp hơn).
  • 23vw → Giá trị mong muốn (23% chiều rộng của cửa sổ trình duyệt).
  • 450px → Giá trị lớn nhất (không bao giờ vượt quá).

Ví dụ

Chiều rộng màn hình23vwKết quả
320px73.6px280px (vì nhỏ hơn min)
768px176.6px280px
1200px276px280px
1400px322px322px
1600px368px368px
2200px506px450px (vì vượt max)

Khi nào dùng?

Ví dụ cho ảnh sản phẩm:

.dmsp-image {
height: clamp(280px, 23vw, 450px);
}
  • Điện thoại → cao 280px.
  • Tablet → khoảng 280–320px.
  • Desktop → khoảng 320–450px.
  • Màn hình siêu rộng → tối đa 450px, không bị quá cao.

Một số giá trị thường dùng

/* Luôn từ 250px đến 400px */
height: clamp(250px, 20vw, 400px);

/* Phù hợp card sản phẩm */
height: clamp(280px, 25vw, 420px);

/* Banner */
height: clamp(300px, 35vw, 700px);

clamp() rất hữu ích vì bạn không cần viết nhiều @media để thay đổi chiều cao theo từng kích thước màn hình.

Thứ Hai, 15 tháng 6, 2026

Click More - Less HTML+JS+CSS

 

** CSS
.filter-list li:nth-child(n+11) {
    display: none;
}
.filter-list.show-all li {
    display: block !important;
}

** JS
<script type="text/javascript">
            
    $(document).on("click", ".moreless", function(e){
        e.stopPropagation();

        var parent = $(this).closest(".filter-section");
        var sublist = parent.find(".filter-list");
        var icon = $(this).find("i");

        if(sublist.hasClass("show-all")){
            sublist.removeClass("show-all");
            $(this).find("span").text("More");

            // icon xuống
            icon.removeClass("fa-angle-up").addClass("fa-angle-down");
        } else {
            sublist.addClass("show-all");
            $(this).find("span").text("Less");

            // icon lên
            icon.removeClass("fa-angle-down").addClass("fa-angle-up");
        }
    });
</script>

** HTML
echo'<div class="filter-section">

    <div class="filter-title">Danh Mục</div>

    <ul class="filter-list">';
        foreach ($data as $key => $value) {
            echo'<li>
                <a href="/'.mod_rewrite($value["title"]).'-'.$value["mid"].'-nsp">'.$value["title"].'</a>
            </li>';
        }
    echo'</ul>

    <button class="moreless toggle-btn"><span>More</span> <i class="ft-icon fa fa-angle-down"></i>
    </button>

</div>';




Thứ Tư, 10 tháng 6, 2026

Icon trong select css đẹp

**** HTML



<div class="select-wrap">

    <select name="customer_shipping_phuongxa" id="customer_shipping_phuongxa">

        <option value="">Chọn Phường / Xã</option>

    </select>

</div> 

**** CSS
.appline .select-wrap{

    position:relative;

    width:100%;

}

.appline .select-wrap select{

    -webkit-appearance:none;

    -moz-appearance:none;

    appearance:none;


    background:#fff;

    border:1px solid #d9d9d9;

    box-sizing:border-box;

    border-radius:16px !important;

    height:40px !important;

    width:100%;

    padding:5px 45px 5px 20px !important;

    transition:all .2s;

    font-size:14px;

    cursor:pointer;

}

.appline .select-wrap select::-ms-expand{

    display:none;

}

.appline .select-wrap:after{

    content:"";

    position:absolute;

    top:50%;

    right:18px;

    margin-top:-2px;

    width:0;

    height:0;

    border-style:solid;

    border-width:5px 4px 0 4px;

    border-color:#888 transparent transparent transparent;

    pointer-events:none;

}

Thứ Tư, 27 tháng 5, 2026

htmlspecialchars show hết lỗi dấu nháy - bird" s

$title_en="bird's nest products";

<input class="form-control" id="txt_name_en" name="txt_name_en" placeholder="Tên sản phẩm - Tiếng anh (*)" value="bird" s="" nest="" products'="" maxlength="80" required="">

và sử dụng hàm htmlspecialchars là OK.

htmlspecialchars($title_en, ENT_QUOTES)