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


当前回答

background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0, #fff), color-stop(0.5, #fff));
background-image: -webkit-linear-gradient(center top, #fff 0%, #fff 50%);
background-image: -moz-linear-gradient(center top, #fff 0%, #fff 50%);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#ffffff', GradientType=0);
background-image: linear-gradient(to bottom, #fff 0%, #fff 50%);

对于旧浏览器..如果你在一些frameworkk .css中定义了css,比如IE9中的select2.css background-image: -webkit-gradient等,你想通过另一个。css重写“background-image: none !important”是不行的。我使用相同的颜色来着色渐变,就像页面背景色一样。

其他回答

div#a {
    background-image: none;
}

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
   }
background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0, #fff), color-stop(0.5, #fff));
background-image: -webkit-linear-gradient(center top, #fff 0%, #fff 50%);
background-image: -moz-linear-gradient(center top, #fff 0%, #fff 50%);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#ffffff', GradientType=0);
background-image: linear-gradient(to bottom, #fff 0%, #fff 50%);

对于旧浏览器..如果你在一些frameworkk .css中定义了css,比如IE9中的select2.css background-image: -webkit-gradient等,你想通过另一个。css重写“background-image: none !important”是不行的。我使用相同的颜色来着色渐变,就像页面背景色一样。

div#a {
  background-image: none !important;
}

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

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

background-size: 0 !important;