Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2014-10-29
9
Medium Priority
?
205 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 58

Accepted Solution

by:
Gary earned 1332 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 84

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 668 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 1332 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article discusses how to implement server side field validation and display customized error messages to the client.
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
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)
Shows how to create a shortcut to site-search Experts Exchange using Google in the Chrome browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch the Search Engine Menu: In chrome, via you…
Suggested Courses

916 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