วิธีการสร้าง: ฟอร์มการล็อกอิน

เรียนรู้วิธีการใช้ CSS ที่จะสร้างฟอร์มการล็อกอินที่เปลี่ยนแปลงตามขนาดหน้าจอ

กดที่ปุ่มเพื่อเปิดฟอร์มการล็อกอิน:

ลองทดลองด้วยตัวเอง

วิธีการสร้างฟอร์มการล็อกอิน

第一步 - 添加 HTML:

เพิ่มรูปภาพเข้าไปในตัวแทนและเพิ่มโคนควบคุมการเข้าถึงข้อมูลในแถวต่างๆ (และตรงกันข้ามกับแทร็ก) ในตัวแทน ใช้องค์ประกอบ <form> ที่วงล้อมมันเพื่อจัดการการเข้าถึงข้อมูล

คุณสามารถดูที่ PHP ความรู้ เพิ่มเติมเกี่ยวกับวิธีการจัดการข้อมูลที่เข้าถึงได้

<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>ชื่อผู้ใช้</b></label>
    <input type="text" placeholder="Enter Username" name="uname" required>
    <label for="psw"><b>รหัสผ่าน</b></label>
    <input type="password" placeholder="Enter Password" name="psw" required>
    <button type="submit">เข้าสู่ระบบ</button>
    <label>
      <input type="checkbox" checked="checked" name="remember"> จดจำฉัน
    </label>
  </div>
  <div class="container" style="background-color:#f1f1f1">
    <button type="button" class="cancelbtn">Cancel</button>
    <span class="psw">ลืม <a href="#">รหัสผ่าน?</a></span>
  </div>
</form>

ขั้นที่ 2 - เพิ่ม CSS:

/* สำหรับตั้งรูปแบบสำหรับฟอร์มที่มีเส้นขอบ */
form {
  border: 3px solid #f1f1f1;
}
/* สำหรับตั้งรูปแบบสำหรับช่องบอกข้อมูลครึ่งกว้าง */
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;
}
/* สำหรับตั้งรูปแบบสไตล์สำหรับทุกปุ่ม */
button {
  background-color: #04AA6D;
  color: white;
  padding: 14px 20px;
  margin: 8px 0;
  border: none;
  cursor: pointer;
  width: 100%;
}
/* 为按钮添加悬停效果 */
button:hover {
  opacity: 0.8;
}
/* 设置取消按钮的额外样式(红色) */
.cancelbtn {
  width: auto;
  padding: 10px 18px;
  background-color: #f44336;
}
/* 将这个容器内的头像图片居中 */
.imgcontainer {
  text-align: center;
  margin: 24px 0 12px 0;
}
/* 头像图片 */
img.avatar {
  width: 40%;
  border-radius: 50%;
}
/* 向容器添加内边距 */
.container {
  padding: 16px;
}
/* "Forgot password" 文本 */
span.psw {
  float: right;
  padding-top: 16px;
}
/* 更改超小屏幕上 span 和取消按钮的样式 */
@media screen and (max-width: 300px) {
  span.psw {
    display: block;
    float: none;
  }
  .cancelbtn {
    width: 100%;
  }
}

ลองทดลองด้วยตัวเอง

如何创建模态登录表单

第一步 - 添加 HTML:

<!-- 打开模式登录表单的按钮 -->
<button onclick="document.getElementById('id01').style.display='block'">Login</button>
<!-- 模态 -->
<div id="id01" class="modal">
  <span onclick="document.getElementById('id01').style.display='none'"
class="close" title="Close Modal">×</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>ชื่อผู้ใช้</b></label>
      <input type="text" placeholder="Enter Username" name="uname" required>
      <label for="psw"><b>รหัสผ่าน</b></label>
      <input type="password" placeholder="Enter Password" name="psw" required>
      <button type="submit">เข้าสู่ระบบ</button>
      <label>
        <input type="checkbox" checked="checked" name="remember"> จดจำฉัน
      </label>
    </div>
    <div class="container" style="background-color:#f1f1f1">
      <button type="button" onclick="document.getElementById('id01').style.display='none'" class="cancelbtn">ยกเลิก</button>
      <span class="psw">ลืม <a href="#">รหัสผ่าน?</a></span>
    </div>
  </form>
</div>

ขั้นที่ 2 - เพิ่ม CSS:

/* โมดอล (พื้นหลัง) */
.modal {
  display: none; /* ซ่อนโดยเริ่มต้น */
  position: fixed; /* อยู่ในที่เดิม */
  z-index: 1; /* ใช้งานด้านบน */
  left: 0;
  top: 0;
  width: 100%; /* ความกว้างเต็ม */
  height: 100%; /* ความสูงเต็ม */
  overflow: auto; /* ใช้การหมุนลูกเวลาถ้าจำเป็น */
  background-color: rgb(0,0,0); /* สีที่เปลี่ยนกลับ */
  background-color: rgba(0,0,0,0.4); /* สีดำที่มีความโปร่งใส */
  padding-top: 60px;
}
/* สาระหรือหน้ามอดัล */
.modal-content {
  background-color: #fefefe;
  margin: 5px auto; /* ห่างจากด้านบน 15% และศูนย์กลาง */
  border: 1px solid #888;
  width: 80%; /* อาจเล็กกว่าหรือใหญ่กว่า ขึ้นอยู่กับขนาดหน้าจอ */
}
/* ปุ่มปิด */
.close {
  /* จัดตั้งตำแหน่งที่ด้านขวาบนของมอดัล */
  position: absolute;
  right: 25px;
  top: 0;
  color: #000;
  font-size: 35px;
  font-weight: bold;
}
/* ปุ่มปิดเมื่อเลื่อนเมาส์เหนือ */
.close:hover,
.close:focus {
  color: red;
  cursor: pointer;
}
/* เพิ่มอนุกรมการยึด */
.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)}
}

คำเตือน:คุณยังสามารถใช้รหัส JavaScript ผ่านการคลิกในพื้นที่นอกหน้าความรู้มอดัลเพื่อปิดมอดัล (ไม่เพียงแค่ใช้ปุ่ม "x" หรือ "cancel"):

<script>
// ดึงมอดัล
var modal = document.getElementById('id01');
// ขณะที่ผู้ใช้คลิกในพื้นที่นอกมอดัล จะปิดมอดัล 
window.onclick = function(event) {
  if (event.target == modal) {
    modal.style.display = "none";
  }
}
</script>

ลองทดลองด้วยตัวเอง

หน้าที่เกี่ยวข้อง

ความรู้:ฟอร์ม HTML

ความรู้:ฟอร์ม CSS