Jump to content


StyleSheet Selection Script


8 replies to this topic

#1 Lastcrime

    Impatient Jedi that likes to eat cereal

  • Members
  • PipPipPip
  • 649 posts
  • Gender:Male
  • Location:Toronto, Ontario, Canada
  • Interests:Soccer, Snowboarding, Hockey, B-ball, Skateboarding, Computers!

Posted 21 August 2007 - 02:50 PM

i no this has been asked before but i couldn't find the topic so im gonna ask again, im not familiar with php at all and i need a script that selects between two stylesheets depending on wether the browser is IE or not ie.

#2 _*Creative Insanity_*

  • Guests

Posted 21 August 2007 - 03:24 PM

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


#3 Lastcrime

    Impatient Jedi that likes to eat cereal

  • Members
  • PipPipPip
  • 649 posts
  • Gender:Male
  • Location:Toronto, Ontario, Canada
  • Interests:Soccer, Snowboarding, Hockey, B-ball, Skateboarding, Computers!

Posted 21 August 2007 - 03:41 PM

View PostCreative Insanity, on Aug 21 2007, 04:24 PM, said:

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

didn't work it says error parsing styles. And when it loads it loads the first style sheet in ie not the one i want it to load heres the code:

<!--
@import url("Stylesheet.css");
-->
<--[if IE]-->
@import url('stylesheet(IE)");
<!--[endif]-->


#4 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 21 August 2007 - 04:23 PM

What Creative showed you is a simple IE conditional.
It is inside of a comment tag, as you'll notice.
All browsers will load the first stylesheet, but IE will see the conditional, and if it reads true, it will execute what is between the comment tags, thus loading the additional stylesheet. All other browsers will regard it as a regular HTML comment, and ignore it.

Use it exactly as Creative has posted, with the conditional correctly nested as the start comment tag. Notice how your's is missing the beginning exclamation point (!).

#5 Lastcrime

    Impatient Jedi that likes to eat cereal

  • Members
  • PipPipPip
  • 649 posts
  • Gender:Male
  • Location:Toronto, Ontario, Canada
  • Interests:Soccer, Snowboarding, Hockey, B-ball, Skateboarding, Computers!

Posted 21 August 2007 - 04:38 PM

o ok i see where i messed up thanks for the explanation.

#6 Lastcrime

    Impatient Jedi that likes to eat cereal

  • Members
  • PipPipPip
  • 649 posts
  • Gender:Male
  • Location:Toronto, Ontario, Canada
  • Interests:Soccer, Snowboarding, Hockey, B-ball, Skateboarding, Computers!

Posted 23 August 2007 - 03:26 PM

alright i put the code in exactly as seen i understand how its hidden from all other browsers but picked up by ie but when i preview in ie it doesn't work it skips the second style sheet and uses the first one (i want it to use the second one.)

heres the code:

<link href="../css/index_stylesheet.css" rel="stylesheet" type="text/css" media="all" />
<!--[if IE 6]>
<link rel="stylesheet" type="text/css" href="Index(IE)_stylesheet.css" media="all" />
<![endif]-->


#7 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 23 August 2007 - 04:05 PM

Well, it will use the first sheet, but the second will take precedence over anything in the first sheet.
In other words, you have to re-write anything IE should show different in the IE-exclusive stylesheet.

#8 Lastcrime

    Impatient Jedi that likes to eat cereal

  • Members
  • PipPipPip
  • 649 posts
  • Gender:Male
  • Location:Toronto, Ontario, Canada
  • Interests:Soccer, Snowboarding, Hockey, B-ball, Skateboarding, Computers!

Posted 23 August 2007 - 04:10 PM

ok so what your saying is if i have this code:

#content{
background-image:...;
margin-left:20px;
margin-top:20px;
in the first stylesheet, and the margin top isn't working properly in ie, so i put this in the second:

#content{
background-image:...;
margin-left:20px;
margin-top:40px;
it will use the margin-top:40px; in the second one?

#9 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 24 August 2007 - 04:42 PM

It should atleast, lol. If it doesn't, then there may be some kinda bug or something.
I personally find it easier to use other IE hacks, such as utilizing the direct descendant selector and such that IE cannot understand. You can Google plenty of ways to do this.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users