Created
May 1, 2011 19:26
-
-
Save nathansmith/950767 to your computer and use it in GitHub Desktop.
Force IE7 & IE8 to respect :last-child
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Heavy-handed way to force IE7 & IE8 to respect :last-child. | |
// Note: Using jQuery. Adjust to suit your library, etc. | |
// | |
// Style via... | |
// | |
// element:last-child, | |
// element.last-child { | |
// /* Style here */ | |
// } | |
// | |
// Yes, I realize this is not performant. But IE7 & IE8 | |
// suck. Those users are probably used to sluggishness. | |
function last_child() { | |
if ($.browser.msie && parseInt($.browser.version, 10) <= 8) { | |
$('*:last-child').addClass('last-child'); | |
} | |
} |
With the new jQuery >= 1.9.0 $.browser
is not more supported. (http://api.jquery.com/jQuery.browser/)
I created a new Gist, which is jQuery 1.9.x compatible:
https://gist.github.com/bytehead/5748928
element:last-child,
element.last-child {
/* Style here */
}
This CSS rule will be skipped in IE7, 8.
IE 7, 8 would skip the whole rule when there are :last-child exist.
It's better to separate into two rules, ie:
element:last-child{
/* Style here */
}
element.last-child {
/* and Style here */
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@webmediahelden
The first-child selector is a part of the CSS2 specification.
So it's available since IE7 ;)