zengun

weblog

20021101

hiding stylesheets from older browsers

Yesterday’s funky mishaps with multiple stylesheets made me wonder how one is supposed to hide multiple stylesheets to older browsers.
While it is possible to have alternate stylesheet with <link> tags, it doesn’t seem to work that well with two <style> tags that @import stylesheets, when in fact both @import statements are executed and used as default style.
So in the end I’m forced to use <link> tags and present Netscape 4 & co. some style that it’ll choke on. Or I could make my stylesheets @import other stylesheets. I’m not fond of russian nesting dolls when it comes to CSS, so if you know another method, there’s a comment form waiting for your wiser input.


10 responses

  1. Michel, what’s the difference between import and the link tag? Is it an xml issue?

    #1 Daynah2002/11/04 at 9:03

  2. Maybe I’m misunderstanding your problem, but have you tried using comment markers? For example:

    #2 Steve — 2002/11/06 at 9:11

  3. D’oh! It didn’t show up, lets try this again… Example:

    <STYLE TYPE=”text/css”>
    <!–
    ABCXYZ {
    xxx-xxx: 123;
    yyy-yyy: 456;
    –>

    #3 Steve — 2002/11/06 at 9:13

  4. Daynah, @import is a CSS command that is not understood by Netscape 4 and lower browsers. This is why it’s mostly used to hide stylesheets from older browsers.
    Steve, the markup I’m using is in my <head> section, it’s commented out (view source).

    #4 michel v — 2002/11/06 at 9:14

  5. D’oh! It didn’t show up… for Example:

    <STYLE TYPE=”text/css”>
    <!–
    ABCXYZ {
    xxx-xxx: 123;
    yyy-yyy: 456;
    }
    –>
    </STYLE>

    #5 Steve — 2002/11/06 at 9:15

  6. Ah I see, but you did it wrong, the comment markers go inside the style tags.

    #6 Steve — 2002/11/06 at 9:18

  7. Yeah. The comments are out of the style tags so that the styme tags really aren’t used! :P
    But I tell you, it’s not a matter of comments (no need to put comments for an @import command). It’s a matter of browsers not understanding the 2 @imported stylesheets are distinct and shouldn’t be used both at once.

    #7 michel v — 2002/11/06 at 9:20

  8. Lol, well then I don’t know what to tell you.

    #8 Steve — 2002/11/06 at 9:29

  9. Hello,
    there are several other ways to hide your css from old/ and not so old browsers
    you can do that with the
    @import rule
    media attribute
    some comments
    attribute, child selectors
    Tantek’s hack
    and …too long
    so here is a good place for information about that
    http://pixels.pixelpark.com/~koch/hide_css_from_browsers/

    and as bonus this is the way (it validate w3c) to comments style

    */–>

    Apologize for my poor english (i’am from belgium)
    cheers

    #9 spoutnik2002/11/08 at 3:28

  10. spoutnik
    made a mistake in the way to comment style
    <style type=”text/css”><!–/*–><![CDATA[/*><!–*/

    /*]]>*/–></style>
    must be ok this time
    I hope so

    #10 spoutnik2002/11/08 at 3:38

Your words


Required fields:
Are marked by this sign: *
XHTML:
You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
On comment spam/irrelevance:
Your comment may be moderated or considered as spam by the leprechauns running this server. If you get a 412 error or a mean message, it may be that they thought it was spam: try wording the comment differently or remind me to put up a contact form so you can warn me about the problem.
Of course, once the leprechauns are done doing their magic, I reserve the right to delete any comment for any reason.