Loading different stylesheets for different browsers

Discussion in 'HTML' started by Andries, Sep 8, 2003.

  1. Andries

    Andries Guest

    I would like my pages to load a specific stylesheet determined by what
    browser the pages will be displayed on. I have found scripts to tell
    me exactly what browser, version etc. is being used, but I am a bit
    confused on exactly what the code should look like to choose the
    correct stylesheet file.

    Any help?
    Andries, Sep 8, 2003
    1. Advertisements

  2. Andries

    Chris Morris Guest

    Advice - don't do this. The HTTP User-Agent: header is not mandatory,
    and may be incorrect even when it does exist. Depending on the
    capabilities of your script, it may even incorrectly detect
    identifiable agents such as Opera. Many browsers identify themselves
    as something else and you can't tell the difference with the UA

    Instead, use the browsers' CSS-parsing capabilities to determine which
    CSS they get to render. This way, you only need one stylesheet.

    Chris Morris, Sep 8, 2003
    1. Advertisements

  3. Toby A Inkster, Sep 8, 2003
  4. Andries

    Sean Jorden Guest

    Here's a question... I want to hide a CSS entry on the HTML tag itself from
    IE. Since this is the top of the tree, I don't think child selectors will
    work. Any ideas?
    Sean Jorden, Sep 8, 2003
  5. Give the HTML a class or ID or some other attribute:

    e.g. <html class="foobar">
    <html id="foobar">
    <html foo="bar">

    and then use an attribute selector in the style sheet:

    html[class=foobar] { color: red; }
    html[id=foobar] { color: red; }
    html[foo=bar] { color: red; }

    In browsers that understand this syntax (only Opera and Gecko AFAIK), this
    will count as more specific than just 'html {...}' in CSS and over-ride
    any declarations made there. However, 'html.foobar {...}' and
    'html#foobar {...}' are even more specific than that, so will over-ride
    'html[class=foobar] {...}' and 'html[id=foobar] {...}'.
    Toby A Inkster, Sep 9, 2003
  6. Andries

    Sean Jorden Guest

    doh! for some reason I was giving <HTML> special status in my mind, it
    didn't even occur to me that it could have and id or class. thanks.
    Sean Jorden, Sep 9, 2003
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.