Cách tạo: Biểu mẫu đăng nhập
- Trang trước Nút quay lên đầu trang
- Trang tiếp theo Hình thức đăng ký
Học cách sử dụng CSS để tạo biểu mẫu đăng nhập响应.
Nhấn nút để mở biểu mẫu đăng nhập:
Cách tạo biểu mẫu đăng nhập
Bước 1 - Thêm HTML:
thêm một hình ảnh vào khung và thêm các điều khiển nhập vào cho mỗi trường (và có thẻ phù hợp). Bọc chúng bằng thẻ <form> để xử lý đầu vào.
Bạn có thể trong Hướng dẫn PHP tìm hiểu thêm về cách xử lý thông tin nhập vào.
<form action="action_page.php" method="post"> <div class="imgcontainer"> <img src="img_avatar2.png" alt="Avatar" class="avatar"> </div> <div class="container"> <label for="uname"><b>Tên người dùng</b></label> <input type="text" placeholder="Nhập tên người dùng" name="uname" required> <label for="psw"><b>Mật khẩu</b></label> <input type="password" placeholder="Nhập mật khẩu" name="psw" required> <button type="submit">Đăng nhập</button> <label> <input type="checkbox" checked="checked" name="remember"> Nhớ tôi </label> </div> <div class="container" style="background-color:#f1f1f1"> <button type="button" class="cancelbtn">Hủy</button> <span class="psw">Quên <a href="#">mật khẩu?</a></span> </div> </form>
Bước 2 - Thêm CSS:
/* Đặt khung cho biểu mẫu có khung */ form { border: 3px solid #f1f1f1; } /* Đặt khung cho các hộp nhập rộng */ input[type=text], input[type=password] { width: 100%; padding: 12px 20px; margin: 8px 0; display: inline-block; border: 1px solid #ccc; box-sizing: border-box; } /* Đặt樣式 cho tất cả các nút */ button { background-color: #04AA6D; color: white; padding: 14px 20px; margin: 8px 0; border: none; cursor: pointer; width: 100%; } /* Thêm hiệu ứng khi di chuột qua nút */ button:hover { opacity: 0.8; } /* Thiết lập phong cách thêm cho nút hủy (màu đỏ) */ .cancelbtn { width: auto; padding: 10px 18px; background-color: #f44336; } /* Đặt ảnh avatar ở giữa trong容器 này */ .imgcontainer { text-align: center; margin: 24px 0 12px 0; } /* Ảnh avatar */ img.avatar { width: 40%; border-radius: 50%; } /* Thêm lề nội bộ cho容器 */ .container { padding: 16px; } /* Văn bản "Quên mật khẩu" */ span.psw { float: right; padding-top: 16px; } /* Thay đổi phong cách cho span và nút hủy trên màn hình siêu nhỏ */ @media screen and (max-width: 300px) { span.psw { display: block; float: none; } .cancelbtn { width: 100%; } }
Cách tạo biểu mẫu đăng nhập mô-đun
Bước 1 - Thêm HTML:
<!-- Nút mở mô-đun biểu mẫu đăng nhập --> <button onclick="document.getElementById('id01').style.display='block'">Đăng nhập</button> <!-- Mô-đun --> <div id="id01" class="modal"> <span onclick="document.getElementById('id01').style.display='none'" class="close" title="Đóng Mô-đun">×</span> <!-- 模态内容 --> <form class="modal-content animate" action="/action_page.php"> <div class="imgcontainer"> <img src="img_avatar2.png" alt="Avatar" class="avatar"> </div> <div class="container"> <label for="uname"><b>Tên người dùng</b></label> <input type="text" placeholder="Nhập tên người dùng" name="uname" required> <label for="psw"><b>Mật khẩu</b></label> <input type="password" placeholder="Nhập mật khẩu" name="psw" required> <button type="submit">Đăng nhập</button> <label> <input type="checkbox" checked="checked" name="remember"> Nhớ tôi </label> </div> <div class="container" style="background-color:#f1f1f1"> <button type="button" onclick="document.getElementById('id01').style.display='none'" class="cancelbtn">Hủy</button> <span class="psw">Quên <a href="#">mật khẩu?</a></span> </div> </form> </div>
Bước 2 - Thêm CSS:
/* Mô đun (bối cảnh) */ .modal { display: none; /* Mặc định là ẩn */ position: fixed; /* Đ停放 lại */ z-index: 1; /* Đặt ở trên cùng */ left: 0; top: 0; width: 100%; /* Rộng toàn bộ */ height: 100%; /* Cao toàn bộ */ overflow: auto; /* Nếu cần, kích hoạt cuộn */ background-color: rgb(0,0,0); /* Màu hồi lại */ background-color: rgba(0,0,0,0.4); /* Đen với độ mờ */ padding-top: 60px; } /* Nội dung/khung mô đun */ .modal-content { background-color: #fefefe; margin: 5px auto; /* Cách trên cùng 15% và居中 */ border: 1px solid #888; width: 80%; /* Có thể nhiều hoặc ít, tùy thuộc vào kích thước màn hình */ } /* Nút đóng */ .close { /* Đặt vị trí ở góc trên bên phải của mô đun */ position: absolute; right: 25px; top: 0; color: #000; font-size: 35px; font-weight: bold; } /* Nút đóng khi hover */ .close:hover, .close:focus { color: red; cursor: pointer; } /* Thêm hiệu ứng phóng to */ .animate { -webkit-animation: animatezoom 0.6s; animation: animatezoom 0.6s } @-webkit-keyframes animatezoom { from {-webkit-transform: scale(0)} to {-webkit-transform: scale(1)} } @keyframes animatezoom { from {transform: scale(0)} to {transform: scale(1)} }
Lưu ý:Bạn có thể sử dụng mã JavaScript để đóng mô đun khi nhấp vào khu vực bên ngoài nội dung mô đun (không chỉ là nút "x" hoặc "hủy bỏ"):
<script> // Lấy mô đun var modal = document.getElementById('id01'); // Khi người dùng nhấp vào bất kỳ vị trí nào ngoài mô đun, hãy đóng nó window.onclick = function(event) { if (event.target == modal) { modal.style.display = "none"; } } </script>
Trang liên quan
Hướng dẫn:Hình thức HTML
Hướng dẫn:Hình thức CSS
- Trang trước Nút quay lên đầu trang
- Trang tiếp theo Hình thức đăng ký