Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS Differentiation based on Browsers

Unsure if possible but just wondering if there is a means in CSS to distinguish between two browsers, i.e. IE6 and IE8 as I have a style that I need to apply, but the value needs to be different for IE6 and IE8, i.e.

ul.sf-menu li li.sfHover ul {
   left:            14.3em; /* for IE8 */
   left:            15em;   /* for IE6 */
   top:             0;

}

Is there anyway when IE8 is being use then use IE8 left style and vice-versa?

Thanks.

like image 915
tonyf Avatar asked Jul 24 '26 07:07

tonyf


2 Answers

You can use different css files, with something like this:

<!--[if IE 6]><link rel="stylesheet" type="text/css" href="../CSS/ie6.css" media="screen" /><![endif]-->
<!--[if IE 7]><link rel="stylesheet" type="text/css" href="../CSS/ie7.css" media="screen" /><![endif]-->

Put all your IE6 "hacks" in one file. When the day comes that IE6 is no more (what a great day!) you can just remove the link. It is quite tidy, rather than within one CSS file.

like image 195
Joe Ratzer Avatar answered Jul 26 '26 04:07

Joe Ratzer


Use Conditional comments to build classes into the the html start tag:

<!Doctype html>
<!--[if IE 6]>
    <html lang="de-DE" class='ie ie6 lte6 lte7 lte8 lte9'>
<![endif]-->
<!--[if IE 7]>
    <html lang="de-DE" class='ie ie7 lte7 lte8 lte9'>
<![endif]-->
<!--[if IE 8]>
    <html lang="de-DE" class='ie ie8 lte8 lte9'>
<![endif]-->
<!--[if IE 9]>
    <html lang="de-DE" class='ie ie9 lte9'>
<![endif]-->
<!--[if !IE]><!-->
    <html lang="de-DE">
<!--<![endif]-->

Be aware: The class attribute is not allowed in HTML 4 for <html>, so use HTML5 and <!Doctype html>.

Now, in your stylesheet you may use these classes:

.ie8
{
    top:        10px;
}
.lte7
{
    top:        15px;
}
like image 27
fuxia Avatar answered Jul 26 '26 04:07

fuxia