如果我理解你,你有表格数据,但你想使用div
元素在浏览器中显示它(AFAIK 表和带有 display:table 的 div 的行为基本相同)。
(这里是一个工作 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 */
}
可悲的是一年前我做不到,当时我真的需要它-_-!