What is better: CSS hacks or browser detection?

后端 未结 15 1697
感情败类
感情败类 2020-12-12 15:28

Commonly when I look around the Internet, I find that people are generally using CSS hacks to make their website look the same in all browsers. Personally, I have found this

15条回答
  •  粉色の甜心
    2020-12-12 16:29

    Is there a reason you use or don't use either of these?

    Yes. Client-side browser-detection breaks if JavaScript is deactivated and might not work correctly with future browser versions. The last reason is also true for CSS hacks. Server-side browser detection breaks if the user explicitly tries to break it, but it still might be a viable alternative.

    What I would recommend:

    Make sure that you're code works in the standars compliant browsers - ie develop in one or two of those and check browsershots.org afterwards. Most likely it will be possible to implement the desired outcome in all of them with one stylesheet.

    Then, there's IE. If there are only a few issues, you could go with a CSS hack. Otherwise, use conditional comments.

    Edit:

    If I have to support ancient browser's as well, I generally go the way of graceful degradation: I'll just let them show the pure html with a basic stylesheet (font sizes, colors, ...). All the fancy stuff will be hidden with an @import rule.

提交回复
热议问题