Solved

CSS IE6 Conditional statement for style sheet not working

Posted on 2009-07-08
16
1,138 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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 500 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
CSS question 16 62
Using the .NET JSON Serializer to create a single string 6 57
Page link not showing on Mobile Device 3 47
Ajax calendar distorted 4 17
CSS is a visual language used to classify objects and define rules about how they should be displayed. CSS skills aren’t restricted to developers anymore, there is a big benefit to having a basic understanding of the language, regardless of your occ…
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

739 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