user1184100
user1184100

Reputation: 6894

li:last-child doesn't seem to work in IE8

Below is my html structure

<div class="footerMenu">
   <ul>
     <li>Home</li>
     <li>About</li>
     <li>Feedback</li>
     <li>Contact us</li>        
   </ul>            
</div>

But

.footerMenu li:last-child { } 

selector doesn't seem to work in IE8. But http://msdn.microsoft.com/en-us/library/cc351024%28VS.85%29.aspx tells that the pseudo-selector is suppported.Any help on this!

Upvotes: 3

Views: 13202

Answers (7)

Walter
Walter

Reputation: 1

I know its old but...there is a simple way to do it:

Just in the li you want the change do this:

<li style="yourstyle;">...</li>

Upvotes: 0

Xella
Xella

Reputation: 1268

Try to use something like that:

.footerMenu li {background-color: expression(this.previousSibling==null?'red':'green');}

Upvotes: 0

BoltClock
BoltClock

Reputation: 723638

You read it wrong. It says that it's not supported in IE8:

If you were looking at :first-child, which does have support in IE7 and IE8, and thinking that the same applies to :last-child... surprise! It doesn't.

:first-child is a CSS2 selector, but :last-child was only introduced in CSS3, so since Microsoft was only aiming for CSS2.1 compliance with IE8, they likely didn't bother about :last-child until post-IE8.

If you know you will only have four li elements, then you should be able to use adjacent sibling selectors to reach the fourth li:

.footerMenu li:first-child + li + li + li

Upvotes: 27

Alex KeySmith
Alex KeySmith

Reputation: 17101

To build on the other guys answers, an alternative could be to use javascript to fill the gaps, selectivizr is a good example of adding last-child support.

http://selectivizr.com/

Upvotes: 2

chipcullen
chipcullen

Reputation: 6960

The other answers are correct that IE8 doesn't support last-child. However, to solve your particular problem, you could either a) manually add a class to the last <li> or b) as this is a menu, and these will presumably have links inside them, target the last link with an attribute selector, which does work in IE8. Something like

.footermenu a[href="contact.html"] { ... }

Upvotes: 0

Ry-
Ry-

Reputation: 224913

Where did you read that? :first-child is supported back to IE7, but :last-child is IE9 and later.

No, it doesn't.

(Headers moved down for your convenience)

Upvotes: 1

Jeff Watkins
Jeff Watkins

Reputation: 6359

The link you provided shows that it isn't supported for IE8... IE9+ only. Googling last-child IE8 brings up a whole host of similar queries.

Upvotes: 1

Related Questions