tags:

views:

59

answers:

5

Hey you guys (and girls),

I have implemented the following CSS:

#tab-navigation ul li:last-child {
    background-image: url(../images/tabs-end.gif);
    background-repeat: no-repeat;
    color: #fff;
    display: block;
    border: 1px solid red;
    background-position: right;
}

However, for some reason this is not working at all in IE (surprise!) - I read (after some research) that IE requires a DOCTYPE, but I already have <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; defined.

Any ideas peeps?

A: 

This table states that last-child isn't supported in any IE browser. Add a class to it and select it that way.

Kyle Sevenoaks
A: 

Simple: IE doesn't support last-child. You'll need to mark the last element with a class.

RoToRa
+1  A: 

IE does not support the :lastchild selector correctly.

For a comprihensive list of compatibility see http://www.quirksmode.org/css/contents.html

I would suggest adding a class="last" server-side to the field, or apply the effect with javascript using http://api.jquery.com/last-child-selector/.

Mex
Thank you Mex, I ended up using: $("#tab-navigation ul li:last-child").css({border:"1px solid red"}) - Thanks.
Neurofluxation
Please note you should only do it this way if...a) You can guarantee that your users have JS enabled.b) Your site is still usable without the effect.
Mex
A: 

The :last-child is a CSS3 selector and as far as I know, even IE8 doesn't support that much.

Resources:

http://www.electrictoolbox.com/css-first-child-last-child-selectors/

Compatibility Chart:

http://www.quirksmode.org/css/contents.html

Sarfraz
+2  A: 

IE doesn't support last-child selector.

You can use scripts such as http://code.google.com/p/ie7-js/ to enable CSS3 selectors in all IE browsers.

Adam
Does this actually work?
Kyle Sevenoaks
Absolutely.http://ie7-js.googlecode.com/svn/test/index.html
Adam
Definitely going to have to look into this!
Kyle Sevenoaks
This set of scripts are very useful. But remember some of your users may not have JS enabled. They may no-script installed for example.
Mex
Agreed Mex, has anyone tried this? How does it degrade (i.e. Gracefully or painfully)?
Neurofluxation
I have used them before. Depends on how heavily you use them. For example if your just using :lastchild to do some hilighting you shouldn't have an issue. If you use the box model fixes or the png hacks you may have more issues.
Mex