如何创建:联系表单
学习如何使用 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 表单