CSS – Select adjacent element

by richard on July 31st, 2009

So, I had a table row with two table cells. The first cell had an class attribute, so I could style it easy enough, but the second table cell had no such class or ID and I need it to style it as well. It should also be noted that i had no means to change the generated html!

Search around a bit and found the CSS adjacent selector. This nifty operator allows me to target the second child within a specified parent. So in my case, the parent was the table row which had an ID, and the children where the two table cells (one with a class and another without). So to get to the second table cell I was able to do:

Viola!

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS