Friday, March 18, 2011

Targeting :first-child on IE6

This article shows a way to target the :first-child pseudoclass on IE6 using an expression to check if previousSibling is null, like so:

table.mytable td
{text-align: expression(this.previousSibling==null?'center':'left');}


Another way I've found is to use the childNodes of the element's parentNode, which is useful for targeting multiple columns in a table (yes, it's a table, but it's being used to display real tabular data in the case I'm working on), and when the col tag isn't enough to style the columns:

table.mytable td
{text-align: expression(this==this.parentNode.childNodes[0]?'center':'left');}

No comments:

Post a Comment