如何創建:聯系表單
學習如何使用 CSS 創建聯系表單。
聯系表單
如何創建聯系表單
第一步 - 添加 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>
第二步 - 添加 CSS:
/* 為類型為 "text" 的輸入框、選擇元素和文本域設置樣式 */ input[type=text], select, textarea { width: 100%; /* 全寬 */ padding: 12px; /* 一些內邊距 */ border: 1px solid #ccc; /* 灰色邊框 */ border-radius: 4px; /* 圓角邊框 */ box-sizing: border-box; /* 確保內邊距和寬度保持不變 */ margin-top: 6px; /* 下外邊距 */ margin-bottom: 16px; /* Bottom margin */ resize: vertical /* 許用戶垂直調整文本域的大小(而不是水平調整) */ } /* 為提交按鈕設置特定的背景顏色等樣式 */ input[type=submit] { background-color: #04AA6D; color: white; padding: 12px 20px; border: none; border-radius: 4px; cursor: pointer; } /* 當鼠標懸停在提交按鈕上時,添加更深的綠色背景 */ input[type=submit]:hover { background-color: #45a049; } /* 為表單容器添加背景顏色和一些內邊距 */ .container { border-radius: 5px; background-color: #f2f2f2; padding: 20px; }
相關頁面
教程:HTML 表單
教程:CSS 表單