【发布时间】:2015-09-05 19:11:46
【问题描述】:
我正在尝试格式化一个两列的表单,以便:
- 标签位于每个输入字段或文本区域的上方
- 类 col1 中的所有内容都在左侧的列中
- 类 col2 中的所有内容都在右侧的列中
- col12 类中的所有内容都跨越两列
这是我需要使用的 HTML 代码:
<div id="contactForm">
<form method="post" action="">
<h3>Contact us</h3>
<p>To send us a work order, fill in the form below.<br /><strong>All the (*) fields are mandatory.</strong></p>
<fieldset>
<div class="col1">
<label for="form_firstname">Firstname <span class="required">*</span></label>
<input type="text" id="form_firstname" name="form_firstname" value="" />
</div>
<div class="col2">
<label for="form_lastname">Lastname <span class="required">*</span></label>
<input type="text" id="form_lastname" name="form_lastname" value="" />
</div>
<div class="col1">
<label for="form_address">Address</label>
<input type="text" id="form_address" name="form_address" value="" />
</div>
<div class="col2">
<label for="form_city">City</label>
<input type="text" id="form_city" name="form_city" value="" />
</div>
<div class="col1">
<label for="form_email">Email <span class="required">*</span></label>
<input type="text" id="form_email" name="form_email" value="" />
</div>
<div class="col2">
<label for="form_phone">Phone <span class="required">*</span></label>
<input type="text" id="form_phone" name="form_phone" value="" />
</div>
<div class="col12">
<label for="form_attachment">Add Attachment <span class="form_attachment">*</span></label>
<textarea id="form_attachment" name="form_attachment" rows="5"></textarea>
</div>
<div class="col12">
<label for="form_message">Message <span class="required">*</span></label>
<textarea id="form_message" name="form_message" rows="5"></textarea>
</div>
<div class="col12">
<label for="form_message">Message <span class="required">*</span></label>
<input type="submit" value="Send" formnovalidate="formnovalidate" />
</div>
</fieldset>
</form>
</div>
如何编码 CSS 以根据需要设置此 HTML 的样式?
这是JSFiddle上的代码。
【问题讨论】:
-
为什么要重新发明轮子,使用Bootstrap、Foundation等前端框架,直到你足够成熟
-
好吧,我宁愿从头做起,也不愿过头。
-
我猜你是对的,有时候这比用无用的样式让你的项目臃肿好..