CSS中的表边框颜色与边框折叠 [英] Table border color in CSS with border collapse

查看:195
本文介绍了CSS中的表边框颜色与边框折叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在表格的某个字段上方添加一行,以表明它是上述值的总和。但是,默认情况下,表格已经有边框。

I want to put a line above some field in a table, to indicate that it is a sum of the above values. However, the table already has borders by default.

这是一个示例:我有一个折叠边框的表格。我在一个字段上设置了border-bottom,在它下面的字段上设置了border-top。这两个都指定相同的边框。使用顶部的CSS。有没有办法使用底部的?

Here is an example: I have a table with borders collapsed. I set the border-bottom on one field, and the border-top on the field below it. Both of these specify the same border. The CSS for the top one is used. Is there a way to use the bottom one?

<html>
    <head>
        <style type="text/css">
            table { border-collapse: collapse; }
            td.first { border-bottom: solid red 1px; }
            td.second { border-top: solid gold 1px; }
        </style>

    <body>
        <table>
            <tr><td class="first">Hello</td></tr>
            <tr><td class="second">World</td></tr>
        </table>
    </body>
</html>

这显示两个单元格之间有红线。有没有办法获得金线?

This shows two cells with a red line between them. Is there way to get a gold line?

推荐答案

这是 border-collapse <的定义行为/ code>。 O'Reilly CSS权威指南第3版的第357页说:

This is a defined behavior of border-collapse. Page 357 of the O'Reilly CSS Definitive Guide 3rd Edition says:


如果折叠边框具有相同的样式和宽度,但颜色不同,然后......从大多数到最不喜欢:单元格,行,行组,列,列组,表格。

if collapsing borders have the same style and width, but differ in color, then ... from most to least preferred: cell, row, row group, column, column group, table.

if ...来自相同类型的元素,例如两行......然后从最顶部和最左边的边界取颜色。

if ... come from same type of element, such as two rows... then color is taken from borders that are the topmost and the leftmost.

所以最上面的,哪个是红色的,胜出。

So the topmost, which is red, wins out.

一种覆盖这种方法的方法可能是使用颜色单元格来赢取行的颜色。

One way to override this may be to use cell for the color to win over the color for the row.

示例: http://jsfiddle.net/Chapm/

优先级高于此相同颜色规则的规则

The rules that have higher precedence than this "same color rule is"


更广泛的边界获胜过窄的

wider border wins over narrower ones

之后,


双赢得胜利,th en dashed,dotted,ridge,outset,groove,inset

double wins over solid, then dashed, dotted, ridge, outset, groove, inset

你可以使用2px作为黄金来赢得它,而我尝试在Chrome中使用 1px double ,它显示为 1px solid 它也将赢得红色。虽然如果你想使用这种方法,那么最好确保你支持的浏览器使用这种技术表现相同。

You can use 2px for the gold for it to win over, and I tried in Chrome to use 1px but double, and it appears as 1px solid and it will win over the red as well. Although if you want to use this method, then it may be best to make sure the browsers you support behave the same using this technique.

http://jsfiddle.net/Chapm/2/

这篇关于CSS中的表边框颜色与边框折叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆