Solved

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

Posted on 2014-10-29
9
192 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
#Citrix #Internet Explorer #Enterprise Mode #IE 11 #IE 8
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

777 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