如果需要,我会在表格中隐藏列。我在 - 标签中使用了 style="display:none"。
用了一段时间,实际上已经不行了...
示例代码:
<table width="100%">
<colgroup>
<col width="auto">
<col width="auto">
<col width="auto">
<col width="auto" style="display: none">
<col width="auto" style="display: none">
<col width="auto">
</colgroup>
<tr>
<th......
</table>
最佳答案
它可能在 IE 7 中有效,因为 IE 7 对列属性的实现是错误的。根据 CSS 2.1 规范,条款 7.1 Columns ,唯一适用于 col
元素的属性(即在设置它们时会产生影响)是 background
、border
、visibility
(仅当设置值 collapse
时)和 width
。此错误已在 IE 8 中修复。
因此,您可以按照评论中的建议设置 visibility: collapse
。如果您发现由于某种原因这种方法不可行,您可以改为在单元格上设置 display
。使一列的所有单元格自然不显示意味着该列根本不显示。由于旧版本的 IE 不支持最简单的方法,您仍然可以保留现在的设置(在 col
上设置 display: none
在CSS,它只是被定义,所以它没有作用):
tr > :nth-child(4), tr > :nth-child(5) {
display: none;
}
<table width="100%" border>
<col>
<col>
<col>
<col style="display: none">
<col style="display: none">
<col>
<tr>
<th>a <th>b <th>c <th>d <th>e <th>f
</table>
为了清楚起见,我添加了 border
属性。我已经删除了 width="auto"
属性,因为它们是无效的并且没有任何效果。设置宽度是一个不同的问题。
关于HTML 表格隐藏列不再起作用了吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26777544/