Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS selector for all table columns greater than nth-of-type(2)?

My current CSS selects the 2nd column:

tr td:nth-of-type(2) {
  padding-left:20px;
  width:100px;
  background-color:yellow;
}

How can I target all columns after the 2nd?

like image 717
HelloWorld Avatar asked Jun 17 '13 19:06

HelloWorld


3 Answers

You could use:

tr td:nth-of-type(2) ~ td

The ~ (general sibling selector) will select all <td> sibling elements after the second one.

Note though that nth-of-type isn't supported in older versions of IE (8 and before).

Alternatively, you could use td:nth-child(n+3) - again this isn't supported in IE8 and before, but if you wanted to use nth-child (not just for this one case obviously) and happen to be using a JavaScript library such as jQuery, there is always Selectivizr, which will make it (and various other selectors) work in IE6 through to IE8.

like image 141
dsgriffin Avatar answered Nov 14 '22 10:11

dsgriffin


this will work...

tr td:nth-of-type(n+3)
{
    padding-left:20px;
    width:100px;
    background-color:yellow;
}

similar question link

like image 36
GAURAV MAHALE Avatar answered Nov 14 '22 10:11

GAURAV MAHALE


td + td + td {

}

Will match the third columns and all columns afterward. This is CSS2 and does not require the "nth-of-type" property - which is not supported in legacy browsers like the browser (IE7) I am using now!

like image 4
ProfileTwist Avatar answered Nov 14 '22 10:11

ProfileTwist