CSS - 调整表格单元格宽度 [英] CSS - adjusting table cell width
本文介绍了CSS - 调整表格单元格宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
让我们来看4个表列 - ID
,文本
,日期
, Action
。在我的case表中总是有恒定的宽度,例如960px。
Let's take 4 table columns - ID
, Text
, Date
, Action
. In my case table have always constant width - in example 960px.
如何创建这样的表:
*-*------------------------------------*----------*----*
|1| Some text... |May 2011 |Edit|
*-*------------------------------------*----------*----*
|2| Another text... |April 2011|Edit|
*-*------------------------------------*----------*----*
如我们所见, ID
,日期
和操作
调整其宽度为内容,
As we can see, ID
, Date
and Action
adjust their width to content, Text
is as long as possible....
是否可以不设置列的特定宽度?当 ID
= 123或日期
= 2011年11月,列应自动更宽...
Is that possible to do without setting specific width of columns ? When ID
= 123 or Date
= November 2011, columns should automatically be wider...
推荐答案
在宽td和表的固定宽度上使用 100%
white-space:nowrap
,可以这样做:
Using a 100%
width on the wide td and a fixed width for the table along with white-space:nowrap
, this can be done:
<table>
<tr>
<td>1</td>
<td width="100%">Some text... </td>
<td>May 2011</td>
<td>Edit</td>
</tr>
<tr>
<td>2</td>
<td width="100%">Another text... </td>
<td>April 2011</td>
<td>Edit</td>
</tr>
</table>
table
{
...
width:960px;
}
td
{
...
white-space:nowrap;
}
这篇关于CSS - 调整表格单元格宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文