หลักสูตรการสร้าง: ฟอร์มลงทะเบียน
- บทความ: หน้าก่อนหน้า
- ฟอร์มการเข้าสู่ระบบ หน้าต่อไป
เรียนรู้ว่าจะสร้างฟอร์มลงทะเบียนที่เหมาะกับ CSS
คลิกปุ่มเพื่อเปิดฟอร์มลงทะเบียน :
หลักสูตรการสร้างฟอร์มลงทะเบียน
ขั้นที่ 1 - เพิ่ม HTML :
ใช้สมรรถนะ <form> สำหรับการจัดการค่าเข้ารหัสออกมา。คุณสามารถพบข้อมูลเพิ่มเติมในหลักสูตร PHP ของเรา。
เพิ่มคอนโทรลสำหรับช่องว่างแต่ละช่อง (และที่มีทายาทที่ตรงกัน) :
<form action="action_page.php" style="border:1px solid #ccc"> <div class="container"> <h1>ลงทะเบียน</h1> <p>โปรดกรอกแบบฟอร์มนี้เพื่อสร้างบัญชี。</p> <hr> <label for="email"><b>อีเมล</b></label> <input type="text" placeholder="ใส่อีเมล" name="email" required> <label for="psw"><b>รหัสผ่าน</b></label> <input type="password" placeholder="ใส่รหัสผ่าน" name="psw" required> <label for="psw-repeat"><b>ยืนยันรหัสผ่าน</b></label> <input type="password" placeholder="ยืนยันรหัสผ่าน" name="psw-repeat" required> <label> <input type="checkbox" checked="checked" name="remember" style="margin-bottom:15px">Remember me </label> <p>โดยที่คุณสร้างบัญชีคุณยอมรับเงื่อนไขและนโยบายส่วนตัวของเรา <a href="#" style="color:dodgerblue">เงื่อนไขและนโยบายส่วนตัว</a>.</p> <div class="clearfix"> <button type="button" class="cancelbtn">Cancel</button> <button type="submit" class="signupbtn">Sign Up</button> </div> </div> </form>
ขั้นที่สอง - เพิ่ม CSS:
* {box-sizing: border-box} /* ช่องว่างกว้างทั้งหมด */ input[type=text], input[type=password] { width: 100%; padding: 15px; margin: 5px 0 22px 0; display: inline-block; border: none; background: #f1f1f1; } input[type=text]:focus, input[type=password]:focus { background-color: #ddd; outline: none; } hr { border: 1px solid #f1f1f1; margin-bottom: 25px; } /* กำหนดสไตล์สำหรับปุ่มทุกตัว */ button { background-color: #04AA6D; color: white; padding: 14px 20px; margin: 8px 0; border: none; cursor: pointer; width: 100%; opacity: 0.9; } button:hover { opacity:1; } /* กำหนดสไตล์เพิ่มเติมสำหรับปุ่มยกเลิก */ .cancelbtn { padding: 14px 20px; background-color: #f44336; } /* ทำให้ปุ่มยกเลิกและปุ่มลงทะเบียนหล่อนและเพิ่มความกว้างที่เท่ากัน */ .cancelbtn, .signupbtn { float: left; width: 50%; } /* เพิ่มเส้นขอบภายในสำหรับองค์ประกอบหลัก */ .container { padding: 16px; } /* ล้างไฟลาท */ .clearfix::after { content: ""; clear: both; display: table; } /* แก้ไขสไตล์ปุ่มยกเลิกและปุ่มลงทะเบียนในหน้าจอที่เล็กที่สุด */ @media screen and (max-width: 300px) { .cancelbtn, .signupbtn { width: 100%; } }
หลักสูตรการสร้างฟอร์มลงทะเบียนโมดอล
ขั้นที่ 1 - เพิ่ม HTML :
ใช้สมรรถนะ <form> สำหรับการจัดการค่าเข้ารหัสออกมา。คุณสามารถพบข้อมูลเพิ่มเติมในหลักสูตร PHP ของเรา。
เพิ่มคอนโทรลสำหรับช่องว่างแต่ละช่อง (และที่มีทายาทที่ตรงกัน) :
<!-- Button to open the modal --> <button onclick="document.getElementById('id01').style.display='block'">Sign Up</button> <!-- The Modal (contains the Sign Up form) --> <div id="id01" class="modal"> <span onclick="document.getElementById('id01').style.display='none'" class="close" title="Close Modal">times;</span> <form class="modal-content" action="/action_page.php"> <div class="container"> <h1>ลงทะเบียน</h1> <p>โปรดกรอกแบบฟอร์มนี้เพื่อสร้างบัญชี。</p> <hr> <label for="email"><b>อีเมล</b></label> <input type="text" placeholder="ใส่อีเมล" name="email" required> <label for="psw"><b>รหัสผ่าน</b></label> <input type="password" placeholder="ใส่รหัสผ่าน" name="psw" required> <label for="psw-repeat"><b>ยืนยันรหัสผ่าน</b></label> <input type="password" placeholder="ยืนยันรหัสผ่าน" name="psw-repeat" required> <label> <input type="checkbox" checked="checked" name="remember" style="margin-bottom:15px"> จดจำฉัน </label> <p>โดยที่คุณสร้างบัญชีคุณยอมรับเงื่อนไขและนโยบายส่วนตัวของเรา <a href="#" style="color:dodgerblue">เงื่อนไขและนโยบายส่วนตัว</a>.</p> <div class="clearfix"> <button type="button" onclick="document.getElementById('id01').style.display='none'" class="cancelbtn">ยกเลิก</button> <button type="submit" class="signup">Sign Up</button> </div> </div> </form> </div>
ขั้นที่สอง - เพิ่ม CSS:
* {box-sizing: border-box} /* ช่องบอกคำกรองความกว้างเต็ม */ input[type=text], input[type=password] { width: 100%; padding: 15px; margin: 5px 0 22px 0; display: inline-block; border: none; background: #f1f1f1; } /* เพิ่มสีพื้นหลังเมื่อตัวเข้าใจถูกเลือก */ input[type=text]:focus, input[type=password]:focus { background-color: #ddd; outline: none; } /* กำหนดสไตล์สำหรับปุ่มทุกตัว */ button { background-color: #04AA6D; color: white; padding: 14px 20px; margin: 8px 0; border: none; cursor: pointer; width: 100%; opacity: 0.9; } button:hover { opacity:1; } /* กำหนดสไตล์เพิ่มเติมสำหรับปุ่มยกเลิก */ .cancelbtn { padding: 14px 20px; background-color: #f44336; } /* ทำให้ปุ่มยกเลิกและลงทะเบียนเลื่อนออกและกำหนดความกว้างเท่ากัน */ .cancelbtn, .signupbtn { float: left; width: 50%; } /* เพิ่มเนื้อหาเนินด้านในสำหรับองค์ประกอบ */ .container { padding: 16px; } /* โมดัล (พื้นหลัง) */ .modal { display: none; /* Hidden by default */ position: fixed; /* Stay in place */ z-index: 1; /* Sit on top */ left: 0; top: 0; width: 100%; /* Full width */ height: 100%; /* Full height */ overflow: auto; /* Enable scroll if needed */ background-color: #474e5d; padding-top: 50px; } /* สนับสนุนเนื้อหา/โมดัล */ .modal-content { background-color: #fefefe; margin: 5% auto 15% auto; /* ห่างจากด้านบน 5% ห่างจากด้านล่าง 15% และศูนย์กลาง */ border: 1px solid #888; width: 80%; /* อาจมากกว่าหรือน้อยกว่า ขึ้นอยู่กับขนาดหน้าจอ */ } /* ตั้งสไตล์เส้นระดับ */ hr { border: 1px solid #f1f1f1; margin-bottom: 25px; } /* ปุ่มปิด (x) */ .close { position: absolute; right: 35px; top: 15px; font-size: 40px; font-weight: bold; color: #f1f1f1; } .close:hover, .close:focus { color: #f44336; cursor: pointer; } /* ล้างเชิงของ */ .clearfix::after { content: ""; clear: both; display: table; } /* แก้ไขสไตล์ปุ่มยกเลิกและปุ่มลงทะเบียนในหน้าจอที่เล็กที่สุด */ @media screen and (max-width: 300px) { .cancelbtn, .signupbtn { width: 100%; } }
คำเตือน:คุณยังสามารถใช้รหัส JavaScript ต่อไปนี้ เพื่อปิดโมดัลโดยคลิกบริเวณนอกเนื้อหาโมดัล (ไม่เพียงแค่ใช้ปุ่ม "×" หรือ "cancel" เท่านั้น):
<script> // รับมอดัล var modal = document.getElementById('id01'); // ขณะที่ผู้ใช้คลิกที่ด้านนอกโมดัล จะปิดมันลง window.onclick = function(event) { if (event.target == modal) { modal.style.display = "none"; } } </script>
ลองทดสอบด้วยตัวเอง
หน้าที่เกี่ยวข้องHTML ฟอร์ม
หน้าที่เกี่ยวข้องCSS ฟอร์ม
- บทความ: หน้าก่อนหน้า
- ฟอร์มการเข้าสู่ระบบ หน้าต่อไป