Solved

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

Posted on 2014-10-29
9
190 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
This article discusses how to create an extensible mechanism for linked drop downs.
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.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

867 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now