我尝试使用CSS将同一字段集中的复选框拆分为两列。
例如,我的代码如下:
<div id="topicsbox">
<label class="topicsname">Topics*</label>
<label class="description">Select topic areas for which you would like to receive future updates from CTU (articles, blog posts, white papers, etc.). Check all that apply:</label>
<div id="topicsmessage" class="messagebox"></div>
<fieldset>
<input type="checkbox" name="topics[]" id="AllTopStories" value="1098375" /><label for="AllTopStories">All Top Stories</label>
<input type="checkbox" name="topics[]" id="BusinessandManagement" value="1098376" /><label for="BusinessandManagement">Business and Management</label>
<input type="checkbox" name="topics[]" id="CareerandProfessional" value="1098377" /><label for="CareerandProfessional">Career and Professional</label>
<input type="checkbox" name="topics[]" id="CriminalJustice" value="1098378" /><label for="CriminalJustice">Criminal Justice</label>
<input type="checkbox" name="topics[]" id="HealthcareAdministration" value="1098379" /><label for="HealthcareAdministration">Healthcare Administration</label>
<input type="checkbox" name="topics[]" id="HomelandSecurity" value="1098380" /><label for="HomelandSecurity">Homeland Security</label>
<input type="checkbox" name="topics[]" id="ITEngineeringComputerScience" value="1098381" /><label for="ITEngineeringComputerScience">IT, Engineering, Computer Science</label>
</fieldset>
</div>
是否有人知道正确的CSS将此列表拆分为左侧的4个输入复选框和右侧的3个输入复选框?
答案 0 :(得分:1)
如何为输入和标签设置css如下:
这样你就可以避免需要一个明确的div,以便你只需要浮动它们
你也可以选择
的CSS3解决方案-moz-column-count:2; /* Firefox */
-webkit-column-count:2; /* Safari and Chrome */
column-count:2;
答案 1 :(得分:0)
CSS中的列计数属性非常有用。如果你在每个表单元素之后放置一个换行符,你可以做一个非常干净的演示文稿。此外,通过添加&lt; span style =“white-space:nowrap;”&gt;“,它会将标签附加到复选框元素
<!DOCTYPE html>
<html>
<head>
<style>
.newspaper {
-webkit-column-count: 2; /* Chrome, Safari, Opera */
-moz-column-count: 2; /* Firefox */
column-count: 2;
}
</style>
</head>
<body>
<p>Here are a bunch of check boxes and their labels laid out nicely
<p><b>Note:</b> Internet Explorer 9, and earlier versions, does not support the column-count property.</p>
<div class="newspaper">
<span style="white-space: nowrap;"><input type="checkbox" name="data" value="some topic" id="some id" /><label for="stuff about a topic">something for you to read</label></span><br/>
<span style="white-space: nowrap;"><input type="checkbox" name="data" value="some topic" id="some id" /><label for="stuff about a topic">something for you to read</label></span><br/>
<span style="white-space: nowrap;"><input type="checkbox" name="data" value="some topic" id="some id" /><label for="stuff about a topic">something for you to read</label></span><br/>
<span style="white-space: nowrap;"><input type="checkbox" name="data" value="some topic" id="some id" /><label for="stuff about a topic">something for you to read</label></span><br/>
<span style="white-space: nowrap;"><input type="checkbox" name="data" value="some topic" id="some id" /><label for="stuff about a topic">something for you to read</label></span><br/>
<span style="white-space: nowrap;"><input type="checkbox" name="data" value="some topic" id="some id" /><label for="stuff about a topic">something for you to read</label></span><br/>
<span style="white-space: nowrap;"><input type="checkbox" name="data" value="some topic" id="some id" /><label for="stuff about a topic">something for you to read</label></span><br/>
<span style="white-space: nowrap;"><input type="checkbox" name="data" value="some topic" id="some id" /><label for="stuff about a topic">something for you to read</label></span><br/>
<span style="white-space: nowrap;"><input type="checkbox" name="data" value="some topic" id="some id" /><label for="stuff about a topic">something for you to read</label></span><br/>
<span style="white-space: nowrap;"><input type="checkbox" name="data" value="some topic" id="some id" /><label for="stuff about a topic">something for you to read</label></span><br/>
<span style="white-space: nowrap;"><input type="checkbox" name="data" value="some topic" id="some id" /><label for="stuff about a topic">something for you to read</label></span><br/>
<span style="white-space: nowrap;"><input type="checkbox" name="data" value="some topic" id="some id" /><label for="stuff about a topic">something for you to read</label></span><br/>
<span style="white-space: nowrap;"><input type="checkbox" name="data" value="some topic" id="some id" /><label for="stuff about a topic">something for you to read</label></span><br/>
<span style="white-space: nowrap;"><input type="checkbox" name="data" value="some topic" id="some id" /><label for="stuff about a topic">something for you to read</label></span><br/>
<span style="white-space: nowrap;"><input type="checkbox" name="data" value="some topic" id="some id" /><label for="stuff about a topic">something for you to read</label></span><br/>
<span style="white-space: nowrap;"><input type="checkbox" name="data" value="some topic" id="some id" /><label for="stuff about a topic">something for you to read</label></span><br/>
<span style="white-space: nowrap;"><input type="checkbox" name="data" value="some topic" id="some id" /><label for="stuff about a topic">something for you to read</label></span><br/>
<span style="white-space: nowrap;"><input type="checkbox" name="data" value="some topic" id="some id" /><label for="stuff about a topic">something for you to read</label></span><br/>
<span style="white-space: nowrap;"><input type="checkbox" name="data" value="some topic" id="some id" /><label for="stuff about a topic">something for you to read</label></span><br/>
<span style="white-space: nowrap;"><input type="checkbox" name="data" value="some topic" id="some id" /><label for="stuff about a topic">something for you to read</label></span><br/>
<span style="white-space: nowrap;"><input type="checkbox" name="data" value="some topic" id="some id" /><label for="stuff about a topic">something for you to read</label></span><br/>
</div>
</body>
</html>