1

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.

3
  • How are you adding the .ie class to your body? Commented May 6, 2014 at 10:21
  • Referred this link stackoverflow.com/questions/11173106/apply-style-only-on-ie and tried it @Paulie_D Commented May 6, 2014 at 10:22
  • 1
    Doesn't answer my question...how are you adding the .ie class? Remember conditional comments are only IE9 and below. Commented May 6, 2014 at 10:24

5 Answers 5

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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 */
}

1 Comment

I need ie specific css for ie10 also
0

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

Comments

0

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)

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.