【发布时间】:2019-07-08 18:16:30
【问题描述】:
我需要创建一个仅使用 HTML 和 CSS 的表单。表单字段的长度取决于它是哪个字段。
我已经尝试了在 SO 和其他使用显示模式之类的网站上找到的几乎所有解决方案,但这些解决方案似乎都针对所有输入字段大小相同的表单。我也尝试使用表格来制作表格,但我对它们的了解不够,无法完成这项工作。如果有人愿意教我如何使用它,我仍然愿意使用桌子。
form {
margin-top: 25px;
}
.form {
margin-left: 10px;
background-color: #fff;
float: left;
width: 620px;
}
.form p {
margin-left: 10px;
}
.form h3,
.summary h3 {
font-size: 36px;
background-color: #fff;
width: auto;
padding-top: 35px;
}
.form label {
font-family: Arial, sans-serif;
font-size: 14px;
display: block;
margin-left: 10px;
color: #8f8f8f;
}
input {
float: left;
margin-left: 10px;
background-color: #f9f9f9;
border: 1px solid #cdcdcd;
height: 36px;
border-radius: 2px;
}
.form span {
color: #861919;
}
.name {
width: 288px;
}
.bigbar {
width: 448px;
}
.smallbar {
width: 128px;
}
<form action="#" method="POST">
<label for="firstname">First Name <span>*</span></label>
<input type="text" id="firstname" required class="name" />
<label for="lastname">Last Name <span>*</span></label>
<input type="text" id="lastname" required class="name" />
<label for="address">Street Address <span>*</span></label>
<input type="text" id="address" required class="bigbar" />
<label for="apt">Apt/Unit/Suite #</label>
<input type="text" id="apt" class="smallbar" />
<label for="city">City <span>*</span></label>
<input type="text" id="city" required class="bigbar" />
<label for="province">Province <span>*</span></label>
<input type="text" id="province" required class="smallbar" />
<label for="code">Postal Code <span>*</span></label>
<input type="text" id="code" required class="smallbar" />
<label for="phone">Phone Number <span>*</span></label>
<input type="tel" id="phone" required class="bigbar" />
<button type="submit" id="submit">Continue Checkout</button>
</form>
最后应该是这样的:https://puu.sh/DQhyH/2aed3ce204.png
但据我所知,它看起来像这样:https://puu.sh/DQhAs/eb0a1eeb5b.png(由于只是创建我的帐户而无法发布图片)
所以它几乎就在那里,但字段没有正确对齐。
【问题讨论】:
-
离题,但为什么“邮政编码”和“电话”在同一行?
-
我猜这正是教练希望的方式。
-
为什么不使用 CSS 使每个元素的大小相同?
input { width: 200px;} -
根据我的作业说明,输入字段的大小应该不同。也许我误解了你在说什么?