Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS Selector for first TD except when containing a colspan

Lets say I have the following table:

<table style="width:500px">
 <tr>
    <td>Col 1</td>
    <td>Col 2</td>
 </tr>
 <tr>
    <td colspan="2"></td>
 </tr>
</table>

Now if I use the first-child selector to apply a style to the first TD, is there anyway I can have it ignore the td that has the colspan (even though of course this is the first-child)?

table tr td:first-child{
  width:100px;
}

I would be happy to give the td with the colspan it's own class name if there was then a way I could modify my selector to say apply to first child except when the class name is x?

like image 685
QFDev Avatar asked Apr 06 '26 06:04

QFDev


2 Answers

use :not([attr="val"])

table tr td:first-child:not([colspan="#NUMBER OF COLSPAN"]){

    width:100px;

}
like image 197
Dhaval Marthak Avatar answered Apr 08 '26 20:04

Dhaval Marthak


Try this:

table tr td:first-child:not(.ignore) {
  width:100px;
}

(Where you give the td that you want to ignore a class of "ignore")

like image 35
mayabelle Avatar answered Apr 08 '26 20:04

mayabelle