6 ms·
After struggling a lot with the browser specific hacks to target IE/Webkit/Whatever, I have now switched to CSS browser selector [1] and never looked back. It s
by niyazpk 16y ago
After struggling a lot with the browser specific hacks to target IE/Webkit/Whatever, I have now switched to CSS browser selector [1] and never looked back. It simply saves a lot of time and effort. If you think about it, the User Agent String is the only accurate information that can be used to sniff the browser name and version, not some random CSS hack.
BTW the article is mostly useless for any practical use. If you really want to target IE6/IE7, this article [2] is a nice start. Learn about what types of bugs IE support and try to remember the name of the bug so that you can google a fix for it when you actually encounter one. As others suggested here, try to understand at least the basics of box model and how it is different in IE, but don't try to get a PhD in any IE bug you encounter. Fix it as fast as you can using whatever easy way out you can see an move on. There are better things to do in life.
[1] https://github.com/rafaelp/css_browser_selector/ https://github.com/rafaelp/css_browser_selector/
[2] http://www.virtuosimedia.com/dev/css/ultimate-ie6-cheatsheet-how-to-fix-25-internet-explorer-6-bugs http://www.virtuosimedia.com/dev/css/ultimate-ie6-cheatsheet...
- Pewpewarrows 16y agoUsing the User Agent String to do anything in CSS or JS is a giant no-no. IE conditional comments, CSS hacks, and feature detection / polyfills are the industry standards. The UA String can be non-existent, mishandled, or just plain-old fabricated.
- pbhjpbhj 16y ago>User Agent String is the only accurate information that can be used to sniff the browser name and version, not some random CSS hack. Those random CSS hacks should always work as they are relying on the specific functions of the UA which can not be altered (though they might clash with new browsers, * html anyone?), whilst as a sibling comment notes UA can be easily modified. Both methods are flawed equally IMO.
- kaylarose 16y agoI find I rarely need to target any browser other than IE with specific styles, so I usually end up doing something like this, which doesn't rely on JS. <!--[if lt IE 7]><html lang="en" class="no-js ie ie6"><![endif]--> <!--[if IE 7]><html lang="en" class="no-js ie ie7"><![endif]--> <!--[if IE 8]><html lang="en" class="no-js ie ie8"><![endif]--> <!--[if IE 9]><html lang="en" class="no-js ie ie9"><![endif]--> <!--[if (gt IE 9)|!(IE)]><!--><html lang="en" class="no-js"><!--<![endif]--> Edit: And then remove the 'no-js' class with js
- Pewpewarrows 16y agoCredit where credit is due: http://paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/ http://paulirish.com/2008/conditional-stylesheets-vs-css-hac...
- kaylarose 16y agoActually I didn't know about that article, but is nice to see the origin of this technique. Mostly took inspiration from HTML5 Boilerplate (also Paul Irish), and previous articles I read. But yes, Paul Irish is awesome, and deserves lots of credit.