abinaya
abinaya

Reputation: 93

IE specific css in CSS file

I want to add ie specific css to a css file.

.center{
margin-top:-40px !important;
}

I tried adding

 .ie .center{
    margin-top:-40px !important;
    }

But this solution doesn't work.Is there any way to do this.

Upvotes: 1

Views: 1036

Answers (5)

Animesh
Animesh

Reputation: 1023

Add this in your head tag

<!--[if IE]>
<link rel="stylesheet" type="text/css" href="ie.css" class="ie" />
<![endif]-->

And paste your css in ie.css

.ie .center{
    margin-top:-40px !important;
}

If you want to target specific versions of IE then for example

<!--[if IE]>
    <link rel="stylesheet" type="text/css" href="ie10.css" class="ie10" />
<![endif]-->

and your respective css in ie10.css would be

.ie10 .center{
        margin-top:-40px !important;
}

Get more IE specific hacks here and here

Upvotes: 0

user3546727
user3546727

Reputation:

Before I placed my answer, I took a look at the other answers posted and I saw your comment

" I need ie specific css for ie10 also"

So I must tell you now that Conditional Comments (that's what those IE specific css appliers are called) were disabled for IE10 and higher since in their point of view, since IE10 they fixed most of the bugs and there was no more need for them.

Upvotes: 0

Jay Patel
Jay Patel

Reputation: 5793

use this. you can use this in your normal style.don't need to make other css file for IE.

.center{
    margin-top:-40px;   /* IE9 and below */
    margin-top:-40px\9; /* IE8 and below */
    *margin-top:-40px;  /* IE7 and below */
    _margin-top:-40px;  /* IE6 */
}

Upvotes: 1

valerio0999
valerio0999

Reputation: 12138

you can either make ie only external stylesheets to target specific versions of IE (or all): http://css-tricks.com/how-to-create-an-ie-only-stylesheet/

or you can use css hacks for specific IE versions: http://css-tricks.com/snippets/css/browser-specific-hacks/

or better, one stylesheet for everybody (best solution)

Upvotes: 0

biolarnative
biolarnative

Reputation: 188

You need to write html IF condition that check if the browser of the client is IE.

<!--[if IE]> <link rel="stylesheet" type="text/css" href="ie.css" /> <![endif]-->

Just so you know it will look for all versions of Internet Explorer. In any case I do not recommend using this method, it's best to one css file for all browsers.

Upvotes: 1

Related Questions