【发布时间】:2010-10-24 11:02:40
【问题描述】:
我有一张表,它的表头上有一个重复的背景图片:
thead tr
{
border-collapse:collapse;
background: #D3D2D2 url(images/background-table-header.gif) repeat-x top;
}
这在 Firefox 和 Internet Explorer 中都适用,但是如果我们希望某些列标题显示排序方向,我们用 Sorted 类和 Direction 来装饰 th。并使用css添加方向图标。
thead th.Sorted
{
background-repeat: no-repeat;
background-position: center left;
padding-left: 0.6em;
}
thead th.Sorted.Ascending
{
background-image: url(images/background-table-sorted-column-ascending.gif);
}
thead th.Sorted.Descending
{
background-image: url(images/background-table-sorted-column-descending.gif);
}
问题在于,在 Internet Explorer 6 和 7 中,来自 tr 的背景颜色被继承(使用 Internet Explorer 开发工具栏发现)到 th。这意味着 th 在 tr 背景上绘制 #D3D2D2 颜色。 Firefox、Chrome 和 IE8 没有这个问题,所以我怀疑这是一个 IE6/7 错误。我曾考虑在thead th.Sorted 上使用background-color:transparant,但IE6/7 只是绘制身体背景(看起来它在身体和th 之间的其他层上切了一个洞)。
它应该是这样的:
这就是它在 IE6 和 IE7 中的样子:
下面是我为这个问题创建的 HTML 片段。
<table cellspacing='0'>
<thead>
<tr>
<th>First column</th>
<th>Second column</th>
<th class="Sorted Ascending">Third column</th>
<th>Fourth column</th>
</tr>
</thead>
<tbody>
<tr>
<td>Data</td>
<td>Data</td>
<td>Data</td>
<td>Data</td>
</tr>
</tbody>
</table>
我该如何解决这个问题?
【问题讨论】:
标签: html cross-browser css