有人知道我如何可以防止文本在表格单元从包装?这是一个表的标题,标题比它下面的数据长得多,但我需要它只显示在一行上。如果柱子很宽也可以。
我的(简化)表格的HTML看起来是这样的:
<table>
<thead>
<tr>
<th>
<div>Really long column heading</div>
</th>
<th>
<div>Really long column heading</div>
</th>
<th>
<div>Really long column heading</div>
</th>
<th>
<div>Really long column heading</div>
</th>
<th>
<div>Really long column heading</div>
</th>
<th>
<div>Really long column heading</div>
</th>
<th>
<div>Really long column heading</div>
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<div>data</div>
</td>
<td>
<div>data</div>
</td>
<td>
<div>data</div>
</td>
<td>
<div>data</div>
</td>
<td>
<div>data</div>
</td>
<td>
<div>data</div>
</td>
<td>
<div>data</div>
</td>
</tr>
</tbody>
</table>
由于页面上的javascript的原因,标题本身被包装在th标签内的div中。
表格出来时,标题被包装成多行。这似乎只发生在表足够宽的情况下,因为浏览器试图避免水平滚动。在我的例子中,我想要水平滚动。
什么好主意吗?
看看white-space属性,是这样使用的:
th {
white-space: nowrap;
}
这将强制<th>的内容显示在一行上。
从链接页面,这里有各种留白的选项:
normal
This value directs user agents to collapse sequences of white space, and break lines as necessary to fill line boxes.
pre
This value prevents user agents from collapsing sequences of white space. Lines are only broken at preserved newline characters.
nowrap
This value collapses white space as for 'normal', but suppresses line breaks within text.
pre-wrap
This value prevents user agents from collapsing sequences of white space. Lines are broken at preserved newline characters, and as necessary to fill line boxes.
pre-line
This value directs user agents to collapse sequences of white space. Lines are broken at preserved newline characters, and as necessary to fill line boxes.
看看white-space属性,是这样使用的:
th {
white-space: nowrap;
}
这将强制<th>的内容显示在一行上。
从链接页面,这里有各种留白的选项:
normal
This value directs user agents to collapse sequences of white space, and break lines as necessary to fill line boxes.
pre
This value prevents user agents from collapsing sequences of white space. Lines are only broken at preserved newline characters.
nowrap
This value collapses white space as for 'normal', but suppresses line breaks within text.
pre-wrap
This value prevents user agents from collapsing sequences of white space. Lines are broken at preserved newline characters, and as necessary to fill line boxes.
pre-line
This value directs user agents to collapse sequences of white space. Lines are broken at preserved newline characters, and as necessary to fill line boxes.