W3C home > Mailing lists > Public > www-style@w3.org > December 2000

Re: help: styling a column with :first-child?

From: Matthew Brealey <webmaster@richinstyle.com>
Date: 7 Dec 2000 16:28:32 -0000
Message-ID: <20001207162832.11809.qmail@phoenix.futurequest.net>
To: www-style@w3.org
You wrote:
> Manos M. Batsis wrote:
> 
> > 
> > Hallo,
> > I'm trying to style every first TD in a table so I give:
> > 
> > table tr:first-child{text-align:left;}
> 
> This selects all tr in a table that are also the first child of
> their parent element, ie of a tbody tfoot or thead. Not cells.
> 
> The effect you are looking for can be achieved with the following
> selector :
> 
>    td:first-child, td:first-child { ... }

Not so:

tr:first-child td:first-child { ... }

is what you we require, although this is, in fact, not correct, since 
although it matches the simple case:

<table>
<tr>
<td>

it doesn't match, for example,

<table>
<col>
<tr>
<td>
</table>

So, you really need selectors that aren't standards yet 
[http://www.w3.org/TR/css3-selectors/]:

table > tr:first-of-type > td:first-of-type,
table > tfoot:first-of-type > tr:first-of-type > td:first-of-type,
table > thead:first-of-type > tr:first-of-type > td:first-of-type,
table > tbody:first-of-type > tr:first-of-type > td:first-of-type,
 {
... declarations
}
(the extra selectors there are necessary, to avoid selecting the trs 
inside tfoots, etc.)

In practice,
tr:first-child td:first-child { ... } will do what you want, because
the fancy table elements really aren't used very much.

-- Random fortune
It's trivial to make fun of Microsoft products, but it takes a real man to
make them work, and a god to make them do anything useful.
Received on Thursday, 7 December 2000 11:28:13 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 27 April 2009 13:54:06 GMT