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
    1. Advertising

  2. Andries

    Chris Morris Guest

    (Andries) writes:
    > 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.


    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
    header.

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

    http://www.w3development.de/css/hide_css_from_browsers/

    --
    Chris
    Chris Morris, Sep 8, 2003
    #2
    1. Advertising

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

    Sean Jorden Guest

    Chris Morris <> wrote in
    news::

    >
    > Instead, use the browsers' CSS-parsing capabilities to determine which
    > CSS they get to render. This way, you only need one stylesheet.
    >
    > http://www.w3development.de/css/hide_css_from_browsers/



    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?


    --
    In theory there is no difference between theory and practice. In practice
    there is. - YB
    Sean Jorden, Sep 8, 2003
    #4
  5. Sean Jorden wrote:

    > 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?


    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 BSc (Hons) ARCS
    Contact Me - http://www.goddamn.co.uk/tobyink/?id=132
    Toby A Inkster, Sep 9, 2003
    #5
  6. Andries

    Sean Jorden Guest

    Toby A Inkster <> wrote in
    news:p:

    > Sean Jorden wrote:
    >
    >> 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?

    >
    > Give the HTML a class or ID or some other attribute:
    >



    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
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?QWxhbiBMYW1iZXJ0?=

    Dynamically loading stylesheets

    =?Utf-8?B?QWxhbiBMYW1iZXJ0?=, Nov 23, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    2,357
    =?Utf-8?B?UGF0cmljay5PLklnZQ==?=
    Nov 24, 2004
  2. Replies:
    2
    Views:
    327
    bruce barker
    Mar 19, 2007
  3. El Kabong

    Browsers, browsers! Quo vadis?

    El Kabong, May 11, 2007, in forum: HTML
    Replies:
    23
    Views:
    873
    dorayme
    May 13, 2007
  4. Sachin
    Replies:
    1
    Views:
    356
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Jun 1, 2007
  5. jim
    Replies:
    1
    Views:
    726
    Wizfrog
    Jul 24, 2007
Loading...

Share This Page