Jorge
Jorge

Reputation: 5676

CSS if statement question

What is the syntax if I want to load a css file in my website with if statement.

Situation is like this.

If ie6 I will load ie6_style.css

and if ie7, mozilla, or new browsers, I will load style.css

Upvotes: 3

Views: 550

Answers (2)

ЯegDwight
ЯegDwight

Reputation: 25257

<link rel="stylesheet" type="text/css" href="style.css">
<!--[if IE 6]>
<link rel="stylesheet" type="text/css" href="ie6_style.css">
<![endif]-->

Upvotes: 9

Dean
Dean

Reputation: 5946

You would need to detect which browser with javascript and then load the CSS.

Something like this

<script language="JavaScript"><!--
browser_version= parseInt(navigator.appVersion);
browser_type = navigator.appName;

if (browser_type == "Microsoft Internet Explorer" && (browser_version >= 7)) {
document.write("<link REL='stylesheet' HREF='012899-ie7.css' TYPE='text/css'>");
}

else if (browser_type == "Netscape" && (browser_version >= 5)) {
document.write("<link REL='stylesheet' HREF='012899-netscape5.css' TYPE='text/css'>");
}

// --></script>

Upvotes: 0

Related Questions