Solved

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

Posted on 2014-10-29
9
195 Views
Last Modified: 2014-11-02
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.
0
Comment
Question by:jazzIIIlove
  • 4
  • 4
9 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40411332
It's pretty much what everyone uses.
0
 
LVL 12

Author Comment

by:jazzIIIlove
ID: 40411382
Yes, but is there any other approach, say more clever and more robust?
0
 
LVL 12

Author Comment

by:jazzIIIlove
ID: 40411387
E.g. does IE 10 support conditional commenting?
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 58

Accepted Solution

by:
Gary earned 333 total points
ID: 40411393
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
 
LVL 83

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 167 total points
ID: 40411418
I think it is generally a bad idea to write pages that need browser targeting.
0
 
LVL 12

Author Comment

by:jazzIIIlove
ID: 40411535
So this is the best way?
0
 
LVL 58

Assisted Solution

by:Gary
Gary earned 333 total points
ID: 40411542
If you have to then yes.
0
 
LVL 12

Author Comment

by:jazzIIIlove
ID: 40411543
Using css trick (assuming that the browser targeting is a solution)?
0
 
LVL 58

Expert Comment

by:Gary
ID: 40411555
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Citrix XenApp, Internet Explorer 11 set to Enterprise Mode and using central hosted sites.xml file.
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Google currently has a new report that is in beta and coming soon to Webmaster Tool accounts. This Micro Tutorial will highlight new features for Google Webmaster Tools.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question