如何在css中删除背景图像?

时间:2009-09-22 16:15:48

标签: html css

我有一个通用规则,它为所有DIV提供背景图像 我有一个div(id ='a'),我不希望它有背景图像 我必须给出什么样的css规则?

10 个答案:

答案 0 :(得分:321)

尝试:

div#a {
    background-image:none
}

答案 1 :(得分:34)

div#a {
    background-image: none;
}

答案 2 :(得分:29)

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

虽然“!important”可能没有必要,因为“div#a”的特异性高于“div”。

答案 3 :(得分:14)

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

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

答案 4 :(得分:8)

因为在css3中,可以设置多个背景图像设置" none"只会创建一个新图层而不会隐藏任何内容。

http://www.css3.info/preview/multiple-backgrounds/ http://www.w3.org/TR/css3-background/#backgrounds

我还没有找到解决方案......

答案 5 :(得分:2)

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%);

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

答案 6 :(得分:1)

如果你的div规则只是div {...},那么#a {...}就足够了。如果它更复杂,则需要一个“更具体”的选择器,由CSS specification on specificity定义。 (#a比div更具体,只是算法中的单个方面。)

答案 7 :(得分:0)

这不起作用:

.clear-background{
background-image: none;
}

可能在旧浏览器上出现问题......

答案 8 :(得分:0)

将您拥有的规则替换为以下内容:

div:not(#a) { // add your bg image here //}

答案 9 :(得分:0)

background-image: none !important;无效时。 您可以使用:

background-size: 0 !important;