我有以下代码:
<td>
<span class='label label-success'>text1</span>
<span class='label label-success'>text2</span>
<span class='label label-success'>text3</span>
<span class='label label-success'>text4</span>
<span class='label label-success'>text5</span>
</td>
我想限制宽度,以便在达到最大宽度时可以在跨度之间获得换行符,如下所示:
text1 text2 text3
text4 text5
假设text4超出了最大宽度。
想法?
答案 0 :(得分:3)
将table-layout:fixed
添加到CSS中的table
标记,然后添加所需的td
宽度,如下所示:
HTML:
<table>
<td>
<span class='label label-success'>text1</span>
<span class='label label-success'>text2</span>
<span class='label label-success'>text3</span>
<span class='label label-success'>text4</span>
<span class='label label-success'>text5</span>
</td>
</table>
CSS:
table {
border: 1px solid #000;
table-layout: fixed;
}
table td {
width: 100px; /* The width you want */
}
这是一个小提琴:http://jsfiddle.net/2mNux/1/
答案 1 :(得分:0)
我认为这样的命令
<td width="200px"> .... </td>
会为你做的伎俩