Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why border of <th> and <thead> both not showing here?

Tags:

css

Why both border not showing?

http://jsfiddle.net/r8mA7/

<table>
<thead style="border-top:10px solid red; background:yellow">
    <tr><th style="border-top:10px solid green">Name</th></tr>
</thead>
<tbody>
    <tr><td>Bob</td></tr>
    <tr><td>Tom</td></tr>
</tbody>
</table>
like image 812
Jitendra Vyas Avatar asked May 07 '10 13:05

Jitendra Vyas


2 Answers

It's the expected behaviour. Odd, but expected.
The borders are collapsing, and the thicker one prevails.

You can see it with this example: the touching borders on first row collapse, the ones on the second row don't.
On the first row the first cell gets the thicker border (10px green > 5px red), and the second cell gets the thicker border (5px red > 3px green).
On the second row there are no "adjoining" borders to collapse, so the 10px green and 3px green borders show up normally.

<table>
<thead style="border-top:5px solid red; background:yellow">
  <tr>
    <th style="border-top:10px solid green">Name</th>
    <th style="border-top:3px solid green">Name</th>
  </tr>
  <tr>
    <th style="border-top:10px solid green">Name</th>
    <th style="border-top:3px solid green">Name</th>
  </tr>
</thead>
</table>

Need me to clear up the explanation anyhow?

PS: theoretically you could use the border-collapse property on the table to prevent that, but I'm not managing.
Also, the default value seems to be not to collapse.

Further reading: http://www.w3.org/TR/CSS2/tables.html#borders

like image 148
ANeves Avatar answered Sep 28 '22 01:09

ANeves


You can use the <thead> element as the selector like this:

thead { background: red; }

You can see an example here

like image 26
Nick Craver Avatar answered Sep 27 '22 23:09

Nick Craver