Elaine Marley Elaine Marley - 5 months ago 27
CSS Question

Border-top from tbody and border-bottom from thead don't work at the same time?

I have a very basic table:

<table id="ttable5" class="table-default">
<th class="sort-date">Provincia</th>
<th class="sort-digit">Municipio</th>

<td class="tablaprim">1VESTIBULUM TORTOR NISL </td>
<td>Castilleja de la Cuesta</td>

<td class="tablaprim">4VESTIBULUM TORTOR NISL </td>
<td>Castilleja de la Cuesta</td>

I need to have this:

------------1px border #fff
------------3px border #gray

I can only get to show one of the borders, never two at the same time. It's not really important but I'm curious about what is causing this issue.

My css:

thead{border-bottom: 1px solid #fff;}
tbody{border-top: 3px solid #4d4d4d;}


Since it seems like the border-collapse might be the issue but I can't make it work I've set up this sandbox:


There you can see there's only a grey border, there should be a 1px white border right on top of it

Answer Source

In order for this to work, you need to

a) use both border-collapse and border-spacing

b) set the borders on the most interior elements of the table

c) you must set border-collapse and border-spacing on the table so it inherits


table {background:pink; 
  border-spacing:0 5px;}

thead tr th{border-bottom: 1px solid red; 
  border-spacing:5px 5px;} 

tbody tr#first td{border-top: 3px solid #4d4d4d; 
  border-spacing:5px 5px;}

I changed some of the colors to make it easier to see.


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download