MẪU WEBSITE THEO GIÁ
Thay đổi dễ dàng theo phong cách của riêng của bạn
NULLTác giả : Số lượt xem : 3833 lượt xem
Modal popup thường xuất hiện rất nhiều trong các trang web, để tạo hiệu ứng hiện popup này chúng ta thường dùng javascript . Sau đây mình xin giới thiệu cho các bạn cách dùng css để tạo nó mà không cần sử dụng bất kì đoạn script nào.
Link DEMO : Bấm vào đây
Trước hết ta có HTML sau:
1 2 3 4 5 6 7 8 9 10 11 |
<div class="wrapper"> <input name="modal" type="checkbox" id="modal"> <label for="modal" class="label-show-modal">Click Modal</label> <div class="modal-show"> <div class="modal-show-inner"> <label for="modal">✖</label> <h2>Show Modal Content</h2> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ac laoreet elit. Phasellus dignissim purus vitae urna cursus, quis congue ligula tristique. Ut nec blandit risus. Donec at orci ut justo venenatis viverra. Suspendisse in volutpat lacus. In enim est, dapibus eget ipsum sed, suscipit ultrices diam.</p> </div> </div> </div> |
Ở html trên ta có :
input – type[checkbox]
label for=”modal” – for label giống id của input để kết nối vs nhau.
Và đây là đoạn css tạo popup mà bạn không phải dùng bất kỳ đoạn script nào :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
body{ margin: 0; } .wrapper{ background: #293a4a; width: 100%; height: 100%; position: fixed; } input{ visibility: hidden; } .label-show-modal{ background: #09b060; border-radius: 0; color: #fff; cursor: pointer; display: inline-block; padding: 10px 15px; font-weight: bold; margin: 20px; } .modal-show { background: rgba(0,0,0,0.7); top: 0; left: 0; right: 0; bottom: 0; position: fixed; text-align: center; opacity: 0; transform: scale(0); visibility: hidden; transition: all 0.75s cubic-bezier(0.19, 1, 0.22, 1); } .modal-show-inner { position: relative; margin: 100px auto 20px; max-width: 500px; width: 80%; color: #fff; background: #09b060; padding: 10px; } .modal-show-inner label{ position: absolute; width: 25px; height: 25px; background: #fff; color: #000; text-align: center; border-radius: 450%; line-height: 25px; top: -12.5px; right: -12.5px; cursor: pointer; } input:checked ~ .modal-show { opacity: 1; transform: scale(1); visibility: visible; transition: all 0.75s cubic-bezier(0.19, 1, 0.22, 1); } |
Thế là song, rất đơn giản phải không. Bạn có thể áp dụng bài viết trên để làm modal popup cho trang web của mình. Bài viết giúp các bạn đang học css có kinh nghiệm thêm về cách sử dụng của nó.
Hy vọng các bạn sẽ thấy thích bài viết của mình chia sẻ cho các bạn, nếu có bất kỳ vấn đề khó khăn gì hay câu hỏi gì . Bạn đừng ngần ngại , hãy để lại bình luận ở dưới nhé.
Chúc Các Bạn Thành Công !