Html 行边框颜色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5288611/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
row border color
提问by DotnetSparrow
I want to set the border of <tr>
to yellow. I can set the border of <td>
but can't figure how to set border of row <tr>
.
How to do this?
我想将 的边框设置<tr>
为黄色。我可以设置边框<td>
但不知道如何设置行边框<tr>
。这该怎么做?
Thanks.
谢谢。
采纳答案by Pete Wilson
No can do, ime, even though css spec ( http://www.w3.org/TR/CSS2/box.html#border-properties) plainly says border and border-color can be applied to "all elements". Though it might be because <table> might not fall under the box model; I'm not sure about this.
即使 css 规范 ( http://www.w3.org/TR/CSS2/box.html#border-properties) 明确表示 border 和 border-color 可以应用于“所有元素” ,我也做不到。虽然可能是因为 <table> 可能不属于盒模型;我不确定这一点。
In any case, it's a counter-intuitive, crazy-seeming, page-bloat-inducing pita.
无论如何,这是一个违反直觉、看起来很疯狂、导致页面膨胀的皮塔饼。
There must be better solutions than bordering every single table cell, which is what I end up doing.
必须有比边界每个表格单元格更好的解决方案,这就是我最终要做的。
-- pete
——皮特
回答by Shadow Wizard is Ear For You
This exampleis working fine on IE8, Chrome 9 and Firefox 3.6 so I really can't see what is the problem.
这个例子在 IE8、Chrome 9 和 Firefox 3.6 上运行良好,所以我真的看不出是什么问题。
HTML used in the example:
示例中使用的 HTML:
<table>
<tr>
<td>AAA</td>
<td class="middle">BBB</td>
<td>CCC</td>
</tr>
</table>
CSS:
CSS:
.middle { border: 2px solid blue; }
tr { border: 2px solid red; }
Result:
结果:
回答by ANeves
It doeswork, and by the spec.
The problem is that the borders collapse, and you did not expect that.
它确实有效,并且符合规范。
问题是边界崩溃了,这是你没想到的。
And by the spec the border for td
tends to dominate over the border for tr
:
http://www.w3.org/TR/CSS2/tables.html#border-conflict-resolution
并且根据规范,边界td
往往超过边界tr
:http:
//www.w3.org/TR/CSS2/tables.html#border-conflict-resolution
回答by Pete Wilson
Write a CSS rule for the tr element? Something like tr {border: ...} Have you tried this and it's not working? Validate your HTML code first with the W3C markup validator and solve the errors if there are any indicated.
为 tr 元素编写 CSS 规则?像 tr {border: ...} 你试过这个但它不起作用吗?首先使用 W3C 标记验证器验证您的 HTML 代码,如果有任何指示,则解决错误。