6

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?

3
  • 1
    Are you declaring your IE only styles before or after you link to your external CSS stylesheet? Commented Aug 22, 2012 at 9:54
  • 1
    Try this background: none !important; Commented Aug 22, 2012 at 9: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. Commented Aug 22, 2012 at 10:03

4 Answers 4

10

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?

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

Comments

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]-->

1 Comment

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!
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]-->

Comments

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

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.