3


Actually I need to specify this property

margin-left:-20px;

only for the IE-11 and the rest of the properties for all browsers in CSS file

.navigator li a span {
    display: block;
    float: right;
    width: 80px;
    height: 50px;
    margin-right: -10px;
    margin-left:-20px;
    }

Is there a way to do that, as I tried many solutions and didn't work
Thanks in advance!

Ulrich Schwarz
  • 7,598
  • 1
  • 36
  • 48
Yasmin
  • 183
  • 1
  • 2
  • 11
  • 6
    Why do you only need `margin-left` for IE? If this is due to a display quirk in IE there may be a better way of handling the issue without resorting to browser sniffing. – Hidden Hobbes Aug 25 '15 at 09:10
  • 2
    Microsoft removed browser specific css from recent browsers, although you can do it with a hack (http://stackoverflow.com/questions/20541306/how-to-write-a-css-hack-for-ie-11) not recommended though! You should try and fix the underlying issue, since ie11 is relatively modern, and should adhere to standards. – Nick R Aug 25 '15 at 09:12
  • 1
    Does your code work on IE10 or others have checked that .? – Himesh Aadeshara Aug 25 '15 at 09:13
  • @NickR hack resolved the issue !
    but the problem is I don't know why that strange behavior happened in IE only.
    – Yasmin Aug 25 '15 at 09:27
  • @HimeshAadeshara Actually I am not interested in IE-10. I am focusing on IE-11 – Yasmin Aug 25 '15 at 09:31
  • @Yasmin, if you provide a full reproducible example we should be able to give you a non-hacky solution and explain what the problem is. – Hidden Hobbes Aug 25 '15 at 09:39
  • @Yasmin Check if your markup is valid - [validator](http://validator.w3.org/). – Vucko Aug 25 '15 at 09:41

2 Answers2

1

It sounds like your problem could be solved in some other way than browser-conditional styles, please try that first, but in any case:

For IE 10 and 11, you can use this:

@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
/* IE10+ CSS styles go here */
}

Note though, that it will recognize both IE 10 and 11.

source: https://philipnewcomer.net/2014/04/target-internet-explorer-10-11-css/

You may also want to take a look at this:

http://marxo.me/target-ie-in-css/


For IE 9 and lower, you can use this:

You create a separate stylesheet for that, and then you use this to include that in your HTML.

source: https://css-tricks.com/how-to-create-an-ie-only-stylesheet/

For example, if you wanted to target IE 7, you would do this. You can just change the version number to what you will.

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

And then you can also target lower or higher versions than a specific version:

Lower than IE 8 and IE 8:

<!--[if lte IE 8]>
    <link rel="stylesheet" type="text/css" href="ie8-and-down.css" />
<![endif]-->

Higher than IE 8:

<!--[if gt IE 8]>
    <link rel="stylesheet" type="text/css" href="ie6-and-up.css" />
<![endif]-->

Note that you can use lt, lte, gt or gte.

Roope
  • 4,469
  • 2
  • 27
  • 51
  • From the very article that you linked to: _“Note that IE 10 and up DO NOT support conditional comments at all.”_ – CBroe Aug 25 '15 at 09:19
  • @CBroe Too bad I just realized that myself as well. So, this does not apply. I have added a solution for IE 10 and 11 as well, though it recognizes both of them. – Roope Aug 25 '15 at 09:19
  • Thank you so much for the help and I'll try this solution as well. – Yasmin Aug 25 '15 at 09:35
1

I wrote is very simple and only supported by IE 11+

<style type="text/css">
  _:-ms-fullscreen, :root .msie11 { color: blue; }
</style>

// or you can try this

<style>
  @media all and (-ms-high-contrast:none)
    {         
      *::-ms-backdrop, .foo { color: red } /* IE11 */
    }
</style>

and of course the div...

<div class="msie11">
    This is an Internet Explorer 11 and greater CSS Hack
<div>

So the text shows up in blue with internet explorer 11 and greater. Have fun with it.

for more reference you can look around with given link

Reference

Community
  • 1
  • 1
Himesh Aadeshara
  • 2,114
  • 16
  • 26
  • @Yasmin honored to help you if you find answer help full you can just accept as answer or you can upvote it – Himesh Aadeshara Aug 25 '15 at 13:23
  • @Yasmin and you should accept any of following answers so that this case can be closed – Himesh Aadeshara Aug 25 '15 at 13:31
  • I tried the second solution(*::-ms-backdrop) and it worked fine with me. Thank you so much for the help. I am sorry for the delay in accepting the answer. I thought that I upgraded and accepted the answer. – Yasmin Aug 30 '15 at 20:29
  • @Yasmin no problem at all,i honored to help you. – Himesh Aadeshara Aug 31 '15 at 04:45
  • Thank you! This helped me so much especially since IE 10 and up DO NOT support conditional comments at all. Your solution helped me fix my own site in modern IE browsers. –  Apr 24 '16 at 19:06