Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Border around tr element doesn't show?

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

How can I set a border on a tr ?

My attempt, which doesn't work:

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

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.

like image 320
edi9999 Avatar asked Sep 07 '13 23:09

edi9999


People also ask

Can TR element have border?

Not directly: adding a border to a tr isn't allowed. But you can target the first and last cell, give those a left/right border respectively. Then on each cell put a top border and a bottom border on each td element.

How do you put a border on a tr tag?

Borders can be added to rows of table by adding border to <td> and <th> elements [This is basically a CSS trick to achieve (hack!) that as borders cannot be added to <tr> and <tbody> elements of table]. Add following styles to your CSS to get borders around rows or headers or table cells.

Why is my border not showing up CSS?

CSS Border Not Showing If you've set the shorthand border property in CSS and the border is not showing, the most likely issue is that you did not define the border style. While the border-width and border-color property values can be omitted, the border-style property must be defined. Otherwise, it will not render.

How do you put a border at the bottom of a TR table?

Solution with the CSS border-bottom property If you want to add a border only to the bottom of the table row, you can apply the CSS border-bottom property to <td> elements that are placed within a <tr> tag.


2 Answers

Add this to the stylesheet:

table {
  border-collapse: collapse;
}

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.

... and later, for collapse setting:

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.

like image 133
raina77ow Avatar answered Sep 22 '22 23:09

raina77ow


It is possible to emulate border in table border collapse separate mode with css box-shadow :

table tr {
  box-shadow: 0 0 4px #ccc;
}
like image 1
Flo Develop Avatar answered Sep 26 '22 23:09

Flo Develop