Code to target browser type and version? Is CSS good enough? Approaches?

Hi;

One version of checking target browser is to add this code to the html-header. All it does is to add a class to the html-tag. The class can then be used in the css code.

Example html

<!DOCTYPE html>
<!--[if IE 7]><html class="no-js ie7 oldie" lang="en"><![endif]-->
<!--[if IE 8]><html class="no-js ie8 oldie" lang="en"><![endif]-->
<!--[if IE 9]><html class="no-js ie9" lang="en"><![endif]-->
<!--[if gt IE 9]><!--><html class="no-js" lang="sv"><!--><![endif]-->

CSS-example

.myclass{ font-size: 20px } /*Default*/
.ie8 .myclass{font-size:10px} /*Override only by ie8*/

But do you think it's robust enough? Any other approach?

Regards.
LVL 12
jazzIIIloveAsked:
Who is Participating?
 
GaryCommented:
There are other hacks like listed here
http://css-tricks.com/snippets/css/browser-specific-hacks/

But the browser specific css is still the easiest

IE10+ dropped support for them, and there should be no need as it behaves pretty much like every other browser.
0
 
GaryCommented:
It's pretty much what everyone uses.
0
 
jazzIIIloveAuthor Commented:
Yes, but is there any other approach, say more clever and more robust?
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
jazzIIIloveAuthor Commented:
E.g. does IE 10 support conditional commenting?
0
 
Dave BaldwinFixer of ProblemsCommented:
I think it is generally a bad idea to write pages that need browser targeting.
0
 
jazzIIIloveAuthor Commented:
So this is the best way?
0
 
GaryCommented:
If you have to then yes.
0
 
jazzIIIloveAuthor Commented:
Using css trick (assuming that the browser targeting is a solution)?
0
 
GaryCommented:
As in your original question.
If it's just the odd css class then use the hacks
Or as David said fix the HTML/CSS so you don't need the hacks, unfortunately it's not always possible with the older browsers.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.