【发布时间】:2015-02-24 01:44:53
【问题描述】:
我有一个空的table 或div 和display:table:
如果我现在向表格添加边框 - 即使没有内容 - 我希望看到边框。
在 Chrome 和 IE 中有一个边框。在 Firefox 中 - 边框占用空间,但它是隐藏的。
DEMO
table,
div {
width: 200px;
background: tomato;
margin-bottom: 20px;
border: 2px solid black;
}
div + div,
table + table {
background: green;
height: 200px;
}
div {
display: table;
}
<div></div>
<div></div>
<table></table>
<table></table>
同样,我什至可以在表格中添加min-height - Chrome 和 IE 都尊重 min-height 属性,但 Firefox 仍然完全隐藏表格。
DEMO
所以为了让表格在 Firefox 中获得高度 - 表格需要内容或 a set height。
所以我想知道:这是一个 firefox 错误,还是规范中没有内容或设置高度的表格被隐藏的正当理由/来源。
【问题讨论】:
-
我倾向于认为它与 With empty <tbody>, only top border in fully-bordered table is displayed 类似于 Bootstrap Issue #13453: table-bordered with tbody and no content = no border 的这个错误有关,您可以使用
table:before{content:"";}强制渲染而不设置高度。 -
在表格中放入所需元素(如行和空单元格或标题)时是否也会出现这种情况?
-
@Reinier Kaper:不,但问题是它们不是必需的。空表是有效的,即使它没有多大意义。
标签: html css firefox cross-browser css-tables