Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apply CSS rules if browser is IE [duplicate]

Possible Duplicate:
How do I do IE conditionals in CSS?

How can I apply the rules below to IE only?

.abc {  float:left; height:0; margin:0 10px; width:0;  /*Apply these rules for IE only*/ position:absolute; left:30; top:-10; /*Apply these rules for IE only*/ } 
like image 461
Mayur Avatar asked Aug 22 '10 15:08

Mayur


People also ask

Can we write browser specific CSS?

When working with HTML and CSS, it is common to face browser-specific issues for the same web application. Therefore, it becomes necessary to develop browser-specific CSS code to assure a seamless user experience, regardless of the browser they use. CSS Grid: CSS Grid is widely used in web design.


2 Answers

In browsers up to and including IE9, this is done through conditional comments.

<!--[if IE]> <style type="text/css">   IE specific CSS rules go here </style> <![endif]--> 
like image 177
2 revs Avatar answered Oct 27 '22 23:10

2 revs


A good way to avoid loading multiple CSS files or to have inline CSS is to hand a class to the body tag depending on the version of Internet Explorer. If you only need general IE hacks, you can do something like this, but it can be extended to be version specific:

<!--[if IE ]><body class="ie"><![endif]--> <!--[if !IE]>--><body><!--<![endif]--> 

Now in your css code, you can simply do:

.ie .abc {   position:absolute;   left:30;   top:-10; } 

This also keeps your CSS files valid, as you do not have to use dirty (and invalid) CSS hacks.

like image 43
DASPRiD Avatar answered Oct 27 '22 21:10

DASPRiD