Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 21st, 2005, 01:50 AM
Andrew Poulos
Guest
 
Posts: n/a
Default td selector question

If I have some HTML that looks like this:

<div class="option">
<table>
<tbody>
<tr>
<td>blah</td>
<td>blah</td>
</tr>
</tbody>
</table>
</div>


How can I create a selector that refers to the first TD and another
selector that refers to the second TD? I'd rather not add a class or id
attribute to the TDs. I've been experimenting with child, descendant etc
selectors but I can't get it working right.

Andrew Poulos
  #2  
Old July 21st, 2005, 01:50 AM
Steve Pugh
Guest
 
Posts: n/a
Default Re: td selector question

Andrew Poulos <ap_prog@hotmail.com> wrote:
[color=blue]
>If I have some HTML that looks like this:
>
><div class="option">
> <table>
> <tbody>
> <tr>
> <td>blah</td>
> <td>blah</td>
> </tr>
> </tbody>
> </table>
></div>
>
>
>How can I create a selector that refers to the first TD and another
>selector that refers to the second TD? I'd rather not add a class or id
>attribute to the TDs. I've been experimenting with child, descendant etc
>selectors but I can't get it working right.[/color]

Does it need to work in IE?

If it does then you need to resort to classes, if it doesn't then
there are a number of possibilities, including :first-child to select
the first one and :last-child to select the last one; td + td to
select the second (and subsequent) cells; CSS3 offers nth-child()
which lets you styles any column you like with ease.

Actually IE can count cells so styling via the DOM is possible with
some JavaScript. By doing this the IE7 package of scripts
http://dean.edwards.name/IE7/ offers support for some of the CSS
selectors mentioned above.

Steve

"My theories appal you, my heresies outrage you,
I never answer letters and you don't like my tie." - The Doctor

Steve Pugh <steve@pugh.net> <http://steve.pugh.net/>
  #3  
Old July 21st, 2005, 01:50 AM
Christoph Paeper
Guest
 
Posts: n/a
Default Re: td selector question

*Steve Pugh* <steve@pugh.net>:[color=blue]
> Andrew Poulos <ap_prog@hotmail.com> wrote:
>[color=green]
>> <table>
>> <tbody>
>> <tr>
>> <td>blah</td>
>> <td>blah</td>
>> </tr>
>> </tbody>
>> </table>
>>
>> How can I create a selector that refers to the first TD and another
>> selector that refers to the second TD? I'd rather not add a class or id[/color]
>
> If it does then you need to resort to classes,[/color]

Some cases can be solved with added 'col's and IE's non-standard support
for them, though. Whether that was an option here, can't be told from that
code fragment.
[color=blue]
> :first-child to select the first one and :last-child to select the last
> one; td + td to select the second (and subsequent) cells; CSS3 offers
> nth-child()[/color]

Just to be clear, ':last-child' is also from CSS*3 Selectors and thus is
not supported by, for instance, Opera*7, but by Gecko. The rest is CSS*2,
but not CSS*1, where MS only claims IE supporting the latter.

--
"What this country needs is more free speech worth listening to."
Hansell B. Duckett
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles