Solved

Conditional statement that switches style sheets in a web page

Posted on 2009-04-08
5
222 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
  • 2
  • 2
5 Comments
 
LVL 42

Accepted Solution

by:
David S. earned 350 total points
Comment Utility
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
Comment Utility
http://www.thesitewizard.com/css/excludecss.shtml will guide u in right direction
0
 
LVL 1

Author Comment

by:gabrielPennyback
Comment Utility
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
Comment Utility
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.
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
In this tutorial viewers will learn how to customize the background color and font color of highlighted text using the ::selection element in CSS Begin by defining the selected text as an element in CSS by typing "::selection": Style the ::selection…
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now