Any ideas on how I can asign different instructions based on browser with in a style sheet without using JS.
Looking to tidy up a few issues between ff and ie in my style sheets.
Any ideas on how I can asign different instructions based on browser with in a style sheet without using JS.
Looking to tidy up a few issues between ff and ie in my style sheets.
There are various css hacks. But, one must be careful! A hack, by definition, isn't supported in any browser. It simply takes advantage of a bug in a given version or versions of a given browser or browsers.
One is the !important hack. In IE 6 and less, it doesn't always mean what it is supposed to. If you have:
width:30px!important;
width:27px;
All browsers are supposed to ignore the second width because it isn't !important. But, IE 6 and less will use 27px, all others (including IE 7) will use 30px.
But, with this and other hacks, one must remember what each does and in which browser(s). There is generally a better way, conditional comments. These are specifically supported in IE 5 and up. With a conditional comment, one may add additional stylesheets for certain or all IE versions, ex:
Now, this should come after the default stylesheet declaration in the head of your document. It doesn't replace it for IE but, anything in it will override the defaults for IE only. To IE, it is simply another stylesheet. To all others, ignored.Code:<!--[if IE]> <link rel="stylesheet" type="text/css" href="ie_only.css"> <![endif]-->
Specific versions can be targeted as well as ranges of versions. Google IE conditional comments for details.
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
or you can use
as IE6 and before doesn't support the import functionalityCode:@import(path.css);
what you do is create your css file and just comment the "IE specific" areas, then link your "overrides" in the @import file.
That's another example of a hack, yes.
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
You can use the downlevel conditional (here, literally - if less than IE 5):
To target all browsers except those IE versions that support conditionals. This is not a hack. The important difference in a downlevel conditional is the absence of dashes. Without those, other browsers do not see it as a comment. IE 5 and up see it as not a comment either but the condition excludes them.Code:<![if lt IE 5]> <link rel="stylesheet" type="text/css" href="all_others.css"> <![endif]>
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
That's not valid HTML though. Instead, you need to do something like:Code:<!--[if !IE]><!-- --> <link rel="stylesheet" type="text/css" href="all_others.css"> <!--<![endif]--><!-- -->
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
That isn't either. A comment declaration begins with "<!" (MDO) and ends with ">" (MDC). Comments within it are delimited by pairs of "--" (COM). Only white space can separate comments, therefore the text "<![endif]" is invalid, as is the end because the final COM is unpaired.
Mike
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
Oh! Stupid me. I was thinking that would cause the first --> and the final <!-- to go unpaired in IE.Ah. Is there any way around that (to hide text only from certain IE versions, for example)?A comment declaration begins with "<!" (MDO) and ends with ">" (MDC). Comments within it are delimited by pairs of "--" (COM). Only white space can separate comments, therefore the text "<![endif]" is invalid, as is the end because the final COM is unpaired.
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
If I understand your question, the easiest way is to break it out and duplicate:
The first "This Isn't IE 7<br>" will be seen only by IE versions less than 7, the second one only by non-IE browsers. IE 7 is the only browser that won't see either of them and no browser will see more than one of them.HTML Code:<div> <!--[if !IE 7]> This Isn't IE 7<br> <![endif]--> <!--[if !IE]>--> This Isn't IE 7<br> <!--<![endif]--> This is all browsers <!--[if IE]> <br>IE Only <![endif]--> </div>
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
Bookmarks