Alex Rivera | Logout

How to select first and last TD in a row?

Asked 2011-08-29T10:17:04.577
188

How can you select the first and the last TD in a row?

tr > td[0],
tr > td[-1] {
/* styles */
}
Edit
Report

1 Answer

21

You can use the following snippet:

  tr td:first-child {text-decoration: underline;}
  tr td:last-child {color: red;}

Using the following pseudo classes:

:first-child means "select this element if it is the first child of its parent".

:last-child means "select this element if it is the last child of its parent".

Only element nodes (HTML tags) are affected, these pseudo-classes ignore text nodes.

answered 2011-08-29T10:19:18.963

Your Answer