วิธีการ - แบบฟอร์มการติดต่อ
เรียนรู้วิธีสร้างแบบฟอร์มการติดต่อด้วย CSS
วิธีสร้างแบบฟอร์มการติดต่อ
ขั้นตอนที่ 1) เพิ่ม HTML
ใช้ <form> องค์ประกอบในการประมวลผลอินพุต คุณสามารถเรียนรู้เพิ่มเติมเกี่ยวกับสิ่งนี้ได้ในบทช่วยสอนPHP ของเรา จากนั้นเพิ่มอินพุต (พร้อมป้ายกำกับที่ตรงกัน) สำหรับแต่ละฟิลด์:
ตัวอย่าง
<div class="container">
<form action="action_page.php">
<label for="fname">First Name</label>
<input type="text"
id="fname" name="firstname" placeholder="Your name..">
<label for="lname">Last Name</label>
<input type="text"
id="lname" name="lastname" placeholder="Your last name..">
<label for="country">Country</label>
<select
id="country" name="country">
<option value="australia">Australia</option>
<option value="canada">Canada</option>
<option value="usa">USA</option>
</select>
<label for="subject">Subject</label>
<textarea
id="subject" name="subject" placeholder="Write something.."
style="height:200px"></textarea>
<input
type="submit" value="Submit">
</form>
</div>
ขั้นตอนที่ 2) เพิ่ม CSS:
ตัวอย่าง
/* Style inputs with type="text", select elements and textareas */
input[type=text], select, textarea {
width: 100%; /*
Full width */
padding: 12px; /* Some padding */
border: 1px solid #ccc;
/* Gray border */
border-radius: 4px; /* Rounded borders */
box-sizing: border-box;
/* Make sure that padding and width stays in place */
margin-top: 6px; /* Add a top margin */
margin-bottom: 16px;
/* Bottom margin */
resize: vertical /* Allow the user
to vertically resize the textarea (not horizontally) */
}
/* Style the submit button with a specific background color etc */
input[type=submit] {
background-color: #04AA6D;
color: white;
padding: 12px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
}
/* When moving the mouse over the submit button,
add a darker green color */
input[type=submit]:hover {
background-color: #45a049;
}
/* Add a background color and some
padding around the form */
.container {
border-radius: 5px;
background-color: #f2f2f2;
padding: 20px;
}
เคล็ดลับ:ไปที่การสอนแบบฟอร์ม HTMLเพื่อเรียนรู้เพิ่มเติมเกี่ยวกับแบบฟอร์ม HTML
เคล็ดลับ:ไปที่CSS Form Tutorialเพื่อเรียนรู้เพิ่มเติมเกี่ยวกับวิธีการจัดรูปแบบองค์ประกอบแบบฟอร์ม
เคยได้ยินเกี่ยวกับW3Schools Spacesไหม? ที่นี่คุณสามารถสร้างเว็บไซต์ของคุณตั้งแต่เริ่มต้นหรือใช้เทมเพลตและโฮสต์ได้ฟรี
เริ่มต้นฟรี ❯* ไม่ต้องใช้บัตรเครดิต