Browser Specific CSS?

Discussion in 'CSS' started by Borduhh, Sep 8, 2010.

  1. #1
    Hello All,

    Is there a way to have a browser specific style sheet?

    Best Regards,
    Nick
     
    Borduhh, Sep 8, 2010 IP
  2. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi,

    For sure there's loads of hacky ways to target certain browsers (most notably IE browsers since they often cause the most hassle).

    Check here for ways to target different versions IE only, either by feeding it a specific stylesheet via the use of conditionals or by using hacks within your current stylesheet.

    What browser are you looking to target here? It's rare you ever need to do this especially for non-IE, provided you are coding correctly, i'd imagine there are a few ways I think if you just Google it. But obviously the most optimal would be to avoid doing this together and solving the real root of the problem!
     
    wd_2k6, Sep 8, 2010 IP
  3. GWiz

    GWiz Peon

    Messages:
    359
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    0
  4. TDub

    TDub Peon

    Messages:
    30
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    JavaScript is nice, but it's not standards compliant. The canonical answer is a resounding "no" and it is supposed to be that way. The only problem with that is all browsers (even on the same platform) render with the slightest differences that it makes me want to scream.

    I've even found bugs in the same version of FF that existed on one platform and not the other.

    Having said all of that, if you are using PHP, you could use this: http://github.com/garetjax/phpbrowscap and then serve up different CSS depending on the browser used (even the version and/or platform).

    So you could have
    <link rel="stylesheet" href="css.php" />

    where css.php analyzes the browser agent and loads the CSS file(s) you specify.
     
    TDub, Oct 3, 2010 IP
  5. drhowarddrfine

    drhowarddrfine Peon

    Messages:
    5,428
    Likes Received:
    95
    Best Answers:
    7
    Trophy Points:
    0
    #5
    Javascript is a ECMA standard and has been for a decade or more. It's allowed in all W3C specifications.
    You can give IE "conditional comments" and serve it it's own CSS as mentioned above.
    What a horrible, horrible idea. You're advocating coding multiple times for multiple browsers. As Olivier told Dustin Hoffman, "Learn how to code, my dear boy!".
     
    drhowarddrfine, Oct 3, 2010 IP