Html tr 元素周围的边框不显示?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18679020/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 13:08:53  来源:igfitidea点击:

Border around tr element doesn't show?

htmlcsshtml-table

提问by edi9999

It seems like Chrome/Firefox do not render borders on tr, but it renders the border if the selector is table tr td.

Chrome/Firefox 似乎不会在 上呈现边框tr,但如果选择器是 ,它会呈现边框table tr td

How can I set a border on a tr ?

如何在 tr 上设置边框?

My try, which doesn't work:

我的尝试,这不起作用:

table tr {
  border: 1px solid black;
}
<table>
  <tbody>
    <tr>
      <td>
        Text
      </td>
    </tr>
  </tbody>
</table>

http://jsfiddle.net/edi9999/VzPN2/

http://jsfiddle.net/edi9999/VzPN2/

This is a similar question: Set border to table tr, works in everything except IE 6 & 7, but it seems to work everywhere except for IE.

这是一个类似的问题:将边框设置为表 tr,适用于除 IE 6 和 7 之外的所有内容,但它似乎适用于除 IE 之外的所有地方。

回答by raina77ow

Add this to the stylesheet:

将此添加到样式表:

table {
  border-collapse: collapse;
}

JSFiddle.

JSFiddle

The reason why it behaves this way is actually described pretty well in the specification:

规范中实际上很好地描述了它以这种方式行事的原因:

There are two distinct models for setting borders on table cells in CSS. One is most suitable for so-called separated borders around individual cells, the other is suitable for borders that are continuous from one end of the table to the other.

在 CSS 中设置表格单元格的边框有两种不同的模型。一种最适用于围绕单个单元格的所谓分离边框,另一种适用于从表格的一端到另一端连续的边框。

... and later, for collapsesetting:

...以及稍后,用于collapse设置:

In the collapsing border model, it is possible to specify borders that surround all or part of a cell, row, row group, column, and column group.

在折叠边框模型中,可以指定包围单元格、行、行组、列和列组的全部或部分的边框。