5

I need to hide a background element in my css for IE.

This is the class in the css file

.navbar-header .nav #presentacion {
    background:url("../img/horiz-line.png") no-repeat scroll 108px 20px transparent;
    display: block;
    height: 20px;
    margin-top: 20px;
}

I want to use this method, inserting the CSS in the head section of the page hidding this part :

    <!--[if IE]>
          <style>
         .navbar-header .nav #presentacion {
         display: block;
         height: 20px;
         margin-top: 20px;
         background: none;}
    </style>
   <![endif]-->

It's not working , the background is still displayed in IE, what i am doing wrong?

Danil Speransky
  • 27,720
  • 3
  • 57
  • 71
Koala7
  • 1,501
  • 6
  • 37
  • 69
  • 1
    Are you declaring your IE only styles before or after you link to your external CSS stylesheet? – Simon West Aug 22 '12 at 09:54
  • 1
    Try this `background: none !important;` – RDX RaN Aug 22 '12 at 09:56
  • note that you do not need to repeat the entire style block, just the background:none; should do. And indeed make sure it comes after the linked stylesheet, inside the head section of your html. – Pevara Aug 22 '12 at 10:03

4 Answers4

8

IE 10 + does not support conditionnal style. So you must use this for IE10+:

<style>
@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
    /* IE10+ styles */
  .navbar-header .nav #presentacion {
         display: block;
         height: 20px;
         margin-top: 20px;
         background: none;}
}
</style>

More info here: How do I target only Internet Explorer 10 for certain situations like Internet Explorer-specific CSS or Internet Explorer-specific JavaScript code?

Community
  • 1
  • 1
nxplace
  • 401
  • 4
  • 4
3

Use the reverse method. Apply !IE class to the class you want to display background image. this gets rendered only in non-IE browsers.

<!--[if !IE]> -->
    <style>
    .navbar-header .nav #presentacion {
    background:url("../img/horiz-line.png") no-repeat scroll 108px 20px transparent;
    display: block;
    height: 20px;
    margin-top: 20px;
    }
    </style>
<!-- <![endif]-->
RDX RaN
  • 197
  • 3
  • 20
Nithin Emmanuel
  • 837
  • 1
  • 8
  • 18
  • great suggestion! more effective, but nowhere near as cool...figure out which version(s) of IE you are targeting, and target them directly. That said, great show of the NOT operator. Well played sir! – albert Aug 22 '12 at 10:25
0

Maybe you declare it before your common stylesheet, and it was overwritten. Try this:

<!--[if IE]>
  <style>
    .navbar-header .nav #presentacion {
      display: block;
      height: 20px;
      margin-top: 20px;
      background: none !important;
    }
  </style>
<![endif]-->
Danil Speransky
  • 27,720
  • 3
  • 57
  • 71
0
 <!--[if IE]>
          <style>
         .navbar-header .nav #presentacion {
         display: block;
         height: 20px;
         margin-top: 20px;
         background-image: none !important;}
    </style>
   <![endif]-->
Prashobh
  • 8,281
  • 14
  • 54
  • 87