我希望表格有100%的宽度,但其中只有一列应该有自由宽度,例如:
| A | B | C |
因此,A和B列的宽度应该与其内容的宽度相匹配,但是C的宽度应该一直持续到表结束。
好吧,我可以以像素为单位指定A和B的宽度,但问题是这些列的内容的宽度不是固定的,所以如果我设置一个固定的宽度,它将不会与内容完全匹配:(
PS:我使用的不是实际的表项,而是一个包装在div中的DL列表。div有display:table,dl有display:table-row,dt/dd display:table-cell ...
发布于 2012-12-30 02:39:27
如果我理解您,您有表格数据,但是您希望使用div
元素在浏览器中显示它(AFAIK table和div with display:table的行为基本相同)。
(这里是一个有效的jsfiddle:http://jsfiddle.net/roimergarcia/CWKRA/)
标记:
<div class='theTable'>
<div class='theRow'>
<div class='theCell' >first</div>
<div class='theCell' >test</div>
<div class='theCell bigCell'>this is long</div>
</div>
<div class='theRow'>
<div class='theCell'>2nd</div>
<div class='theCell'>more test</div>
<div class='theCell'>it is still long</div>
</div>
</div>
和CSS:
.theTable{
display:table;
width:95%; /* or whatever width for your table*/
}
.theRow{display:table-row}
.theCell{
display:table-cell;
padding: 0px 2px; /* just some padding, if needed*/
white-space: pre; /* this will avoid line breaks*/
}
.bigCell{
width:100%; /* this will shrink other cells */
}
可悲的是,一年前,当我真的需要它的时候,我无法做到这一点- -_-!
https://stackoverflow.com/questions/14084221
复制相似问题