我正在尝试在无序列表中创建两列。我有点成功,但是,我不想指定ul
和li span
的宽度,而是占用其父级的所有宽度(即div
)。我该怎么做?感谢
CSS
div {
width:300px;
}
ul {
width:200px;
}
li span {
width: 170px;
display:inline-block;
padding-left: 10px;
vertical-align: top;
}
HTML
<div>
<ul>
<li>
<input type="checkbox" value="1" name="someName[]"><span>Some short text</span>
</li>
<li>
<input type="checkbox" value="2" name="someName[]"><span>Some very very very very very very long text</span>
</li>
<li>
<input type="checkbox" value="3" name="someName[]"><span>Some short text</span>
</li>
</ul>
</div>
答案 0 :(得分:1)
如果您不关心支持IE7,可以使用display: table
和display: table-cell
:
li { display: table; }
li > * { display: table-cell }
答案 1 :(得分:0)
用
替换你的CSSdiv {
}
ul {
}
li span {
display:inline-block;
padding-left: 10px;
vertical-align: top;
}
答案 2 :(得分:0)
div {
width:300px;
}
li input {
position: absolute;
}
li span {
display: inline-block;
margin-left: 30px;
vertical-align: top;
}