【问题标题】:How to show borders of th elements with gradient fills in IE9?如何在 IE9 中显示带有渐变填充的元素的边框?
【发布时间】:2011-07-06 14:49:51
【问题描述】:

我希望表格的标题单元格具有特定的边框颜色和渐变填充。我希望它看起来像这样:

这是上面的html:

<!DOCTYPE html>
<html>

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<link href="styles.css" rel="stylesheet" type="text/css">
</head>

<body>
    <table>
        <thead>
            <tr>
                <th>Column00</th>
                <th>Column01</th>
                <th>Column02</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>Feline</td>
                <td>Cat</td>
                <td>Felidae</td>
            </tr>
            <tr>
                <td>Canine</td>
                <td>Dog</td>
                <td>Caninae</td>
            </tr>
            <tr>
                <td>Primate</td>
                <td>Ape</td>
                <td>Primates</td>
            </tr>
        </tbody>
    </table>
</body>

</html>

这是css:

table{
    border-collapse: collapse;
}

th{
    border: 3px #449944 solid;
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#44bb44'); /* IE */
    background: -webkit-gradient(linear, left top, left bottom, from(#ffffff), to(#44bb44)); /* Chrome */
    background: -moz-linear-gradient(top, rgba(255,255,255,1), rgba(85,205,85, 1));
}

它在 Chrome 12 和 Firefox 5 中完美显示,但在 IE 9 中看起来像这样:

看起来 IE9 将渐变填充放在边框顶部。如何让 IE9 “在顶部”显示 TH 元素的边框?

TIA。

【问题讨论】:

  • 可能是边框折叠问题。试试th{ border-collapse: no-collapse;
  • 完全正确 - 但还必须设置 TH 元素的边框
  • @Kyle Sevenoaks:尝试了您的建议,但似乎没有任何影响......
  • @user639175: “...但是 TH 元素的边框也必须设置”。我已经设置了 TH 元素的边框宽度、颜色和样式。我应该设置其他属性吗?
  • @couche:你关心的只有IE9吗? IE8 或更低版本重要吗?

标签: html css internet-explorer-9 border gradient


【解决方案1】:

这似乎是一个众所周知的IE9 中的错误(?): 渐变背景“溢出”边框。当使用带有渐变填充的圆角时,这一点尤其明显(这些在 Chrome 和 FF 中完美显示,但在 IE 中,渐变填充延伸到圆角之外)。请参阅此 SO 问题的答案:IE9 border-radius and background gradient bleeding。

目前最简单的解决方案是在 IE 中使用在 x 方向重复的渐变填充的良好背景图像,如下所示:

table{
    border-collapse: collapse;
}

th{
    border: 3px #449944 solid;
    background-image: url('greenGradient.png');
    background-repeat: repeat-x;
    background: -webkit-gradient(linear, left top, left bottom, from(#ffffff), to(#44bb44)); /* Chrome */
    background: -moz-linear-gradient(top, rgba(255,255,255,1), rgba(85,205,85, 1));
}

然后 IE 会表现并“在顶部”显示边框,而背景填充会保持在边框内,正如人们所期望的那样。

【讨论】:

  • 感谢 couche 的工作就像一个魅力。不敢相信 IE9 会以这种方式呈现过滤器。还有很长的路要走...
【解决方案2】:

http://msdn.microsoft.com/en-us/library/ie/jj127314(v=vs.85).aspx

"padding-box:背景被绘制在(剪辑到)填充框内。" 将 TH 上的背景剪辑属性设置为“填充框”应该可以解决问题

【讨论】:

    【解决方案3】:

    它是 TABLE 元素上的边框折叠,然后是边框宽度 ...

    【讨论】:

    • 嗨 - 我尝试在 TABLE 元素上将边框折叠设置为不折叠,然后在对我和我有意义的所有可能组合中设置 TABLE 和 TH 元素的边框宽度仍然无法获得我在问题中发布的第一张图片的外观。我是否正确理解了您的建议?
    • 是的 - 对不起,我没有帮忙 - 我会在白天做一个实验......回复你:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-28
    • 2012-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-29
    相关资源
    最近更新 更多