如何创建 - 联系人部分
了解如何为网页创建响应式联系人部分。
联系人页面
亲自试一试 »创建联系人部分
步骤 1) 添加 HTML:
实例
<div class="container">
<div style="text-align:center">
<h2>Contact Us</h2>
<p>Swing by for a cup of coffee, or
leave us a message:</p>
</div>
<div class="row">
<div class="column">
<img src="/w3images/map.jpg"
style="width:100%">
</div>
<div class="column">
<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:170px"></textarea>
<input type="submit" value="Submit">
</form>
</div>
</div>
</div>
步骤 2) 添加 CSS:
实例
* {
box-sizing: border-box;
}
/* 样式输入 */
input[type=text], select, textarea {
width: 100%;
padding: 12px;
border: 1px solid #ccc;
margin-top: 6px;
margin-bottom: 16px;
resize: vertical;
}
input[type=submit] {
background-color: #4CAF50;
color: white;
padding: 12px 20px;
border: none;
cursor: pointer;
}
input[type=submit]:hover {
background-color: #45a049;
}
/* 设置容器/联系人部分的样式 */
.container {
border-radius: 5px;
background-color: #f2f2f2;
padding: 10px;
}
/* 创建两个彼此相邻浮动的列 */
.column {
float: left;
width: 50%;
margin-top: 6px;
padding: 20px;
}
/* 在列之后清除浮动 */
.row:after {
content: "";
display: table;
clear: both;
}
/* 响应式布局 - 当屏幕宽度小于 600px 时,使两列堆叠在一起而不是彼此相邻 */
@media screen and (max-width:
600px) {
.column, input[type=submit] {
width: 100%;
margin-top: 0;
}
}
亲自试一试 »