如果存在 rowspan,Chrome 不支持行高 [英] Chrome doesn't honor row height if rowspan is present
问题描述
我想制作一个表格,其中的单元格跨越两行.第二行的高度尺寸必须尽可能小.示例:
I want to make a table with a cell that spans on two rows. The second row must have the height size as minimum as possible. Example:
html:
<table>
<tr id="row-1">
<td>
1st row
</td>
<td rowspan="2">
a <br />
a <br />
a <br />
a <br />
a <br />
a <br />
a <br />
a <br />
</td>
</tr>
<tr id="row-2">
<td>
2nd row
</td>
</tr>
</table>
CSS:
td
{
border: 1px solid black;
}
#row-2
{
height: 1px;
}
它适用于 Firefox (19.0.2).在 Chromium (25.0.1364.160) 上,高度最小的行是第一行!
It works on Firefox (19.0.2). On Chromium (25.0.1364.160), the row with the minimum height is the first one!
问题是由这个错误引起的:http://code.google.com/p/chromium/issues/detail?id=78724
The problem is caused by this bug: http://code.google.com/p/chromium/issues/detail?id=78724
我怎样才能用 CSS 破解它?目前我正在使用 JS,将第一行的高度设置为等于行跨单元格的高度减去第二行的高度.
How can I hack it with CSS? Currently I'm using JS, setting the 1st row height equal to the height of the rowspan cell minus the height of the second row.
推荐答案
发现:诀窍是将另一个表格放在具有非 rowspan 内容的表格的单元格内,从另一个单元格中移除 rowspan 并设置外部和内表高度为 100%.可怕但有效.
Found: the trick is to put another table inside a cell of the table with the non-rowspan content, remove the rowspan from the other cell and set the outer and inner table height to 100%. Horrible but effective.
HTML:
<table id="outer"><tbody><tr>
<td>
<table id="inner"><tbody>
<tr id="row-1">
<td>1st row</td>
</tr>
<tr id="row-2">
<td>2nd row</td>
</tr>
</tbody></table>
</td>
<td>
a<br />
a<br />
a<br />
a<br />
a<br />
a<br />
a<br />
a<br />
a<br />
</td>
</tr></tbody></table>
CSS:
#row-2
{
height: 1px;
}
#outer, #inner
{
height:100%;
}
这篇关于如果存在 rowspan,Chrome 不支持行高的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!