我有一个通用规则,给所有div一个背景图像。 我有一个div (id='a'),我不希望它有背景图像。 我需要给出什么css规则呢?


当前回答

当background-image: none !没有效果。 你可以使用:

background-size: 0 !important;

其他回答

div#a {
    background-image: none;
}
div#a {
  background-image: url('../images/spacer.png');
  background-image: none !important;
}

我使用了一个透明的间隔图像,除了规则来删除背景图像,因为IE6似乎忽略了background-image: none,即使它被标记为!important。

HTML:

<div id="a" class="mydiv"></div>    

CSS:

div#a {
       background-image:none;
}

另一种方法:

div:not(#a) {
     //all rules goes here 
     //add image here
     //div with id a not effected by these rules
   }

多重(非伪)

   div:not(#a):not(#b):not(#c) {
     //all rules goes here 
     //add image here
     //div with ids not effected with these rules
   }
div#a {
  background-image: none !important;
}

虽然“!”重要”可能没有必要,因为“div#a”比“div”具有更高的特异性。

Try:

div#a {
    background-image:none
}