...">

Apply style to first row cells

It should be very simple, but I can’t understand.

I have a table like this:

<table class="category_table"> <tr><td> blabla 1</td><td> blabla 2 </td></tr> <tr><td> blabla 3 </td><td> blabla 4 </td></tr> </table> 

I want the td tags of the first line tr have vertical-align . But not the second line.

 .category_table td{ vertical-align:top; } 
+54
html css html-table css-selectors
May 04 '12 at 13:51
source share
3 answers

Use tr:first-child to carry the first tr :

 .category_table tr:first-child td { vertical-align: top; } 

If you have nested tables and don’t want to apply styles to the inner rows, add some child selectors so that only the top td level on the first top level tr will get the styles:

 .category_table > tbody > tr:first-child > td { vertical-align: top; } 
+119
May 04 '12 at 13:54
source share

This should do the job:

 .category_table tr:first-child td { vertical-align: top; } 
+3
May 4 '12 at 1:54 pm
source share

Below is the first table tr table under thead

 table thead tr:first-child { background: #f2f2f2; } 

And this works for the first tr of thead and tbody both:

 table thead tbody tr:first-child { background: #f2f2f2; } 
0
Sep 05 '16 at 0:05
source share



All Articles