Solved

Conditional statement that switches style sheets in a web page

Posted on 2009-04-08
5
227 Views
Last Modified: 2012-05-06
I need a conditional statement for IE6 (and lower) in the header of my web page that will switch style sheets from the default style1.css to style2.css.

Thanks,

John
0
Comment
Question by:gabrielPennyback
[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
  • 2
  • 2
5 Comments
 
LVL 42

Accepted Solution

by:
David S. earned 350 total points
ID: 24103935
You can use a regular stylesheet and then override any styles that need to be different in IE in the IE-specific stylesheet without having to maintain two completely separate stylesheets.

Here's the code:
<!--[if lte IE 6]><link rel="stylesheet" type="text/css" href="ie_styles.css" /><![endif]-->

Open in new window

0
 
LVL 9

Assisted Solution

by:Sreedhar Vengala
Sreedhar Vengala earned 150 total points
ID: 24103954
http://www.thesitewizard.com/css/excludecss.shtml will guide u in right direction
0
 
LVL 1

Author Comment

by:gabrielPennyback
ID: 24103985
Okay, here's my real-life example. This particular page has 4 style sheets. My "ie_styles.css" might have to have overrides of all 4 of them. I suppose that's not a problem as long as I put it last, right?

For that matter can you put the IE6 conditional statements in the css itself so that
     background: url(images/image1.png);
          could be replaced with this in IE6:
     background: url(images/image2.jpg);
or whatever

If so, how would that be stated exactly?

Thanks.


<link href="/css/global.css" rel="stylesheet" type="text/css" />
<link href="css/greenStuff.css" rel="stylesheet" type="text/css" />
<link href="css/dimensions_index.css" rel="stylesheet" type="text/css" />
<link href="css/SimpleDropdown.css" rel="stylesheet" type="text/css" />
<!--[if lte IE 6]><link rel="stylesheet" type="text/css" href="css/ie_styles.css" /><![endif]-->

Open in new window

0
 
LVL 1

Author Closing Comment

by:gabrielPennyback
ID: 31568382
Thanks. If you can, please let me know the proper syntax for overriding a particular style within the css itself, assuming that's something that can be done.
-John
0
 
LVL 42

Expert Comment

by:David S.
ID: 24104248
You just make another rule that has the same selector as the first rule. Wherever there is more than one declaration for the same property in rules that have the same the specificity, the last declaration is the one that will be used, unless overridden by a rule that has a higher specificity.

In short, the cascade is a wonderful thing.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
This article discusses how to implement server side field validation and display customized error messages to the client.
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 …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

707 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