วิธีการ - แบบฟอร์มอินไลน์
เรียนรู้วิธีสร้างแบบฟอร์มอินไลน์ที่ตอบสนองด้วย CSS
แบบฟอร์มอินไลน์ที่ตอบสนอง
ปรับขนาดหน้าต่างเบราว์เซอร์เพื่อดูเอฟเฟกต์ (ป้ายกำกับและอินพุตจะซ้อนกันแทนที่จะอยู่ติดกันบนหน้าจอขนาดเล็ก):
วิธีสร้างแบบฟอร์มอินไลน์
ขั้นตอนที่ 1) เพิ่ม HTML
ใช้ <form> องค์ประกอบในการประมวลผลอินพุต คุณสามารถเรียนรู้เพิ่มเติมเกี่ยวกับสิ่งนี้ได้ในบทช่วยสอนPHP ของเรา
ตัวอย่าง
<form class="form-inline" action="/action_page.php">
<label
for="email">Email:</label>
<input type="email" id="email"
placeholder="Enter email" name="email">
<label for="pwd">Password:</label>
<input type="password" id="pwd" placeholder="Enter password" name="pswd">
<label>
<input type="checkbox" name="remember"> Remember me
</label>
<button type="submit">Submit</button>
</form>
ขั้นตอนที่ 2) เพิ่ม CSS:
ตัวอย่าง
/* Style the form - display items horizontally */
.form-inline {
display: flex;
flex-flow: row wrap;
align-items: center;
}
/* Add some margins for each label */
.form-inline label {
margin: 5px 10px 5px 0;
}
/* Style the input fields */
.form-inline input {
vertical-align: middle;
margin:
5px 10px 5px 0;
padding: 10px;
background-color: #fff;
border: 1px solid #ddd;
}
/* Style the submit button */
.form-inline button {
padding: 10px 20px;
background-color: dodgerblue;
border: 1px solid #ddd;
color: white;
}
.form-inline button:hover
{
background-color: royalblue;
}
/* Add responsiveness -
display the form controls vertically instead of horizontally on screens that
are less than 800px wide */
@media (max-width: 800px) {
.form-inline input {
margin: 10px 0;
}
.form-inline {
flex-direction: column;
align-items: stretch;
}
}
เคล็ดลับ:ไปที่การสอนแบบฟอร์ม HTMLเพื่อเรียนรู้เพิ่มเติมเกี่ยวกับแบบฟอร์ม HTML
เคล็ดลับ:ไปที่CSS Form Tutorialเพื่อเรียนรู้เพิ่มเติมเกี่ยวกับวิธีการจัดรูปแบบองค์ประกอบแบบฟอร์ม