7 replies [Last post]
fhinixrizin
Offline
newbie
Last seen: 6 years 29 weeks ago
Joined: 2007-12-30
Posts: 4
Points: 0

Can anyone see why this conditional stylesheet statement does not work. The first stylesheet is for firefox and most other browsers. The second, conditional stylesheet is to to fix IE bugs. I have also tried another version also with a negative test to see if the browser is not IE [if !IE] for the main stylesheet which makes neither stylesheet load. I have been looking in all my css books and online and cannot figure out why my conditional statements are not working. Since I know the individual stylesheets commands work by themselves if placed by themselves (the ie stylesheet works for IE and not for firefox if it is in the file by itself and the firefox or other browser stylesheet works for firefox if placed in the file by itself) in the file, I have to conclude that the conditional statements do not work. I will include samples of both:

Original Version - The first stylesheet always loads. If I remove the first stylesheet code and take the if off the second, the image formats correctly in IE and not in Firefox. If it runs the way as written below, it formats in firefox but not in IE.

THE DEFINITE GUIDE TO STYLE FOR THE MODERN MAN

Alternate Version with Negative test - Neither stylesheet loads - I get plain content

THE DEFINITE GUIDE TO STYLE FOR THE MODERN MAN

jinoturistica
Offline
Enthusiast
Jinotega, Nicaragua
Last seen: 6 years 21 weeks ago
Jinotega, Nicaragua
Timezone: GMT-6
Joined: 2007-11-16
Posts: 152
Points: 0

stu nichols to the rescue

You can't get there from here. legally.

from the brain of Stu Nichols at http://www.cssplay.co.uk/menu/conditional.html comes this solution.

IE sees the [if !IE] and the [endif] as a 5 line structure that is not true and thus not executed and the standard CSS is not loaded.

Firefox sees 3 things
1. <!--[if !IE]><!--> as a one-line comment, ignores it
2. a load statement for css - loads the standard CSS file
3. <!--<![endif]--> as a one-line comment, ignores it

Just doin' my best at www.jinotega.com
Tony Robins

Tyssen
Tyssen's picture
Offline
Moderator
Brisbane
Last seen: 48 weeks 3 days ago
Brisbane
Timezone: GMT+10
Joined: 2004-05-01
Posts: 8201
Points: 1386

It would be more helpful if

It would be more helpful if you described in better detail what you're trying to do and what's contained in the different stylesheets. There shouldn't be any need to hide your main stylesheet from IE; you just need to include certain rules in an IE-only sheet to overcome its bugs.

How to get help
Post a link. If you can't post a link, jsFiddle it.
My blog | My older articles | CSS Reference

fhinixrizin
Offline
newbie
Last seen: 6 years 29 weeks ago
Joined: 2007-12-30
Posts: 4
Points: 0

reply to stu nicholss

I don't get what you are saying and the alternate code, or the second code example does not load either stylesheet in firefox. The page loads as an unformatted page.

fhinixrizin
Offline
newbie
Last seen: 6 years 29 weeks ago
Joined: 2007-12-30
Posts: 4
Points: 0

reply to tyssen

The first stylesheet is for firefox and other browsers. While the second stylesheet is to fix IE browser bugs. The stylesheet conditional statement are not working.

jinoturistica
Offline
Enthusiast
Jinotega, Nicaragua
Last seen: 6 years 21 weeks ago
Jinotega, Nicaragua
Timezone: GMT-6
Joined: 2007-11-16
Posts: 152
Points: 0

Your code doesn't work and

Your code doesn't work and cannot work as coded.

The code I put here does work, I tested it in both browsers. here it is again.

Throw your stuff away, paste mine in and it'll work. Have faith!

Tyssen is right. You should have a main always-loaded CSS for standards then the ie.css comes in for IE users and does some overrides. Much easier for maintenance that way.

Just doin' my best at www.jinotega.com
Tony Robins

fhinixrizin
Offline
newbie
Last seen: 6 years 29 weeks ago
Joined: 2007-12-30
Posts: 4
Points: 0

reply to jinoturistica

Thank you, your change does work. May I ask what the additions you added do? Also without the condition around the first stylesheet, the second one never works. If you look at my first example, it is coded without the if statement on the primary stylesheet. Online and in my CSS books I did not find any examples like the code you sent.

jinoturistica
Offline
Enthusiast
Jinotega, Nicaragua
Last seen: 6 years 21 weeks ago
Jinotega, Nicaragua
Timezone: GMT-6
Joined: 2007-11-16
Posts: 152
Points: 0

go to stu nichols!

To make the first sheet work and the second only work in IE, delete lines 1 and 3. In Firefox you'll have 1 style sheet, in IE, you'll have 2.

It's all about what a browser 'sees'. Only IE sees that stuff inside [..], only IE cares about an [if] being finished with an [endif].

Take that first 5 line statement. Consider what Firefox 'sees' - delete all the [..] - whats the first line now? Just a meaningless comment. Same for the 5th line. Lines 2/3/4 are a link that gets executed - BY FIREFOX.

Now take that same 5 lines, put on your programmers hat, what does IE 'see'? An [IF..] statement that later on will need an [ENDIF] statement, everything between those is the body that might, or might not, get executed depending on the truth of the IF statement. Hold on! The IF is not true, we ARE running IE. Throw everything away until we get to an [ENDIF]. In the garbage is the link to the Firefox CSS.

Sorry, can't explain it any simpler. Use it, check it, move on. Ain't worth worrying about. I've been writing web pages since the early 90's and never used conditional statements yet. Now I've seen them, courtesy your problem, I'm even less impressed than I was. Reminds me of conditional JCL on MVS.

Stu Nichols wrote it, please ask him if you really think its worth the candle.

Just doin' my best at www.jinotega.com
Tony Robins