Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apply CSS rule to only the first <td> in <tr>'s WITHOUT assigning a class/id?

I have already viewed this, it's not what I need here..

I need something like

table.mytable tr first-td's { border: 1px solid black; }

for

<table class="mytable">
<tr>
<td>This has the border</td>
<td>no border</td>
<td>no border</td>
</tr>
<tr>
<td>This has the border</td>
<td>no border</td>
<td>no border</td>
</tr>
<tr>
<td>This has the border</td>
<td>no border</td>
<td>no border</td>
</tr>
</table>

If this is impossible just let me know and I'll be sad.

Javascript/jQuery is acceptable if it's needed to get the job done.

like image 839
khaverim Avatar asked Aug 14 '12 19:08

khaverim


1 Answers

table.mytable tr td:first-child { border: 1px solid black; }

https://developer.mozilla.org/en-US/docs/CSS/:first-child

Works in jQuery too ( http://api.jquery.com/first-child-selector/ ):

$('table.mytable tr td:first-child')
like image 79
Blazemonger Avatar answered Oct 20 '22 12:10

Blazemonger