?
Solved

CSS IE6 Conditional statement for style sheet not working

Posted on 2009-07-08
16
Medium Priority
?
1,149 Views
Last Modified: 2012-06-27
Hi Guys,
I have an ASPX page which has two conditional statements, i want to display a different stylesheet if an IE6 user is on my page....my statements are

1)for the style sheet:
<!--[if IE 6]>
<link href="IE6.css" rel="stylesheet" type="text/css" />
<![endif]-->

2) for a paragraph of text
    <!--[if IE 6]>
<h1>This is for IE 6 Only</h1>
<![endif]-->

the paragraph conditional statement works fine in IE 6 but my style sheet statement does not, any ideas what im doing wrong? attached is my code.

Thanks
Jay
********************
My Page Default.aspx
********************
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml" >
<!--[if IE 6]>
<link href="IE6.css" rel="stylesheet" type="text/css" />
<![endif]-->
<link href="allbrowsers.css" rel="stylesheet" type="text/css" />
 
<head runat="server">
    <title>CSS Style Sheet Swap</title>
</head>
<body>
<center>    <form id="form1" runat="server">
    <div id ="header">
    
    <h1>All Browsers Can See This</h1>
    
    
    <!--[if IE 6]>
<h1>This is for IE 6 Only</h1>
<![endif]-->
 
    </div>
    </form>
    </center>
 
</body>
</html>
 
 
********************
IE6 Stylesheet
********************
body {
	background-color: #CCFFFF;
}
 
body, td, th {
	color: #333333;
}
 
h1, h2 {
	color: #000033;
}
 
h3, h4, h5, h6 {
	color: #006699;
}
 
a {
  color: #003366;
}
#header
{
    width:800px;
    height:500px;
    background-color:green;
    margin-left:-20px;
}
 
 
********************
All Browsers Stylesheet
********************
body {
	background-color: #003366;
}
 
body {
	color: #DEDECA;
}
 
td, th {
	color: #99CCCC;
}
 
h1 {
	color: #FFFF33;
}
 
h2 {
	color: #FFFF66;
}
 
h3, h4 {
	color: #FFFFCC;
}
 
h5, h6 {
	color: #6699CC;
}
 
a {
	color: #9999cc;
}
#header
{
    width:800px;
    height:50px;
    background-color:Red;
}

Open in new window

0
Comment
Question by:jay_eire
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 7
16 Comments
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 24808664
use <% %>

is this your actual code?

also, did you want to load the allbrowser css? if so load the IE6 css after to override any elements

=NerdsOfTech
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml" >
<!--// <% if IE 6 %> //-->
<link href="IE6.css" rel="stylesheet" type="text/css" />
<!--// <% else %> //-->
<link href="allbrowsers.css" rel="stylesheet" type="text/css" />
<!--// <% endif %> //-->
 
<head runat="server">
    <title>CSS Style Sheet Swap</title>
</head>
<body>
<center>    <form id="form1" runat="server">
    <div id ="header">
    
    <h1>All Browsers Can See This</h1>
    
    
<!--// <% if IE 6 %> //-->
<h1>This is for IE 6 Only</h1>
<!--// <% end if %> //-->
 
    </div>
    </form>
    </center>
 
</body>
</html>

Open in new window

0
 
LVL 7

Author Comment

by:jay_eire
ID: 24808713
thanks for the reply, yep this is my code, im just trying to get the switch working for the stylesheet, i copied and pasted your code in but im getting this error back

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1003: Syntax error, '(' expected

Source Error:

 

Line 4:  
Line 5:  <html xmlns="http://www.w3.org/1999/xhtml" >
Line 6:  <!--// <% if IE 6 %> //-->
Line 7:  <link href="IE6.css" rel="stylesheet" type="text/css" />
Line 8:  <!--// <% else %> //-->
 
0
 
LVL 7

Author Comment

by:jay_eire
ID: 24808734
I want to allow both style sheets, if the user accesses my site using IE6 to use the IE6 stylesheet if they are using any other browser then the page loads the allbrowsers.css
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 24808803
Thats why I questioned your code

the syntax for if is

if (condition){
 statement;
}
0
 
LVL 7

Author Comment

by:jay_eire
ID: 24808841
ok thanks, so how should the if statement look in my code??
0
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 24808862
to you have the
Request.ServerVariables["HTTP_USER_AGENT"];

code already setup?
0
 
LVL 7

Author Comment

by:jay_eire
ID: 24808891
no i dont how do i set that up? im trying to do this inline on the page, im totally lost here :(
0
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 24808972
Are you familiar with C# ?
0
 
LVL 7

Author Comment

by:jay_eire
ID: 24809026
no sorry im not, i thought this would be a quick bit of inline code to get the stylesheets switched, i will be using the statement on an ASPX but i cannot even get it working in a html file.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Untitled Page</title>
    <!--[if IE 6]>
<link href="IE6.css" rel="stylesheet" type="text/css" />
<![endif]-->
<link href="allbrowsers.css" rel="stylesheet" type="text/css" />
</head>
<body>
 <center>
        <div id ="header">
    
    <h1>All Browsers Can See This</h1>
    
    
    <!--[if IE 6]>
<h1>This is for IE 6 Only</h1>
<![endif]-->
 
    </div>
    </center>
</body>
</html>

Open in new window

0
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 24809101
rename your file with prefix .asp

like
default.asp
or something else
.asp

we will be using asp 1 for this
0
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 24809111
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml" >
<%
Dim strBrowser
StrBrowser = Request.ServerVariables("HTTP_USER_AGENT")
If (Left(strBrowser, 4) = "MSIE") Then %>
<link href="IE6.css" rel="stylesheet" type="text/css" />
<% Else %>
<link href="allbrowsers.css" rel="stylesheet" type="text/css" />
<% End If %>
 
<head runat="server">
    <title>CSS Style Sheet Swap</title>
</head>
<body>
<center>    <form id="form1" runat="server">
    <div id ="header">
   
    <h1>All Browsers Can See This</h1>
   

<% If (Left(strBrowser, 4) = "MSIE") Then %>
<h1>This is for IE 6 Only</h1>
<% End If %>
 
    </div>
    </form>
    </center>
 
</body>
</html>
0
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 24809113

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml" >
<%
Dim strBrowser
StrBrowser = Request.ServerVariables("HTTP_USER_AGENT")
If (Left(strBrowser, 4) = "MSIE") Then %>
<link href="IE6.css" rel="stylesheet" type="text/css" />
<% Else %>
<link href="allbrowsers.css" rel="stylesheet" type="text/css" />
<% End If %>
 
<head runat="server">
    <title>CSS Style Sheet Swap</title>
</head>
<body>
<center>    <form id="form1" runat="server">
    <div id ="header">
   
    <h1>All Browsers Can See This</h1>
   
 
<% If (Left(strBrowser, 4) = "MSIE") Then %>
<h1>This is for IE 6 Only</h1>
<% End If %>
 
    </div>
    </form>
    </center>
 
</body>
</html>

Open in new window

0
 
LVL 7

Author Comment

by:jay_eire
ID: 24809144
but the statement needs to work on an  ASPX page on the .net framework 3.5
0
 
LVL 7

Author Comment

by:jay_eire
ID: 24809227
I moved my original CSS conditional statement from between the HEAD tags into the body of my page and it worked.


<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml" >
 
<link href="allbrowsers.css" rel="stylesheet" type="text/css" />
 
<head runat="server">
    <title>CSS Style Sheet Swap</title>
</head>
<body>
<!--[if IE 6]>
<link href="IE6.css" rel="stylesheet" type="text/css" />
<![endif]-->
<center>    <form id="form1" runat="server">
    <div id ="header">
    
    <h1>All Browsers Can See This</h1>
    
    
    <!--[if IE 6]>
<h1>This is for IE 6 Only</h1>
<![endif]-->
 
    </div>
    </form>
    </center>
 
</body>
</html>

Open in new window

0
 
LVL 42

Accepted Solution

by:
David S. earned 2000 total points
ID: 24810822
You don't need to move it from between the head tags. You just need to move it after the main stylesheet.

You see, declarations in a stylesheet override declarations in a previous stylesheet where there are conflicts. It's the "cascading" part of CSS. And because of that you only need to include the declarations that are different in the IE6 stylesheet instead of having two complete stylesheets.
0
 
LVL 7

Author Closing Comment

by:jay_eire
ID: 31601314
Thank you.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question