Html 如何删除css中的背景图像?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1461077/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I remove background-image in css?
提问by Itay Moav -Malimovka
I have a general rule which gives all DIVs a background image.
I have one div (with id='a') which I don't want it to have the background image.
What css rule do I have to give it?
我有一个通用规则,它为所有 DIV 提供背景图像。
我有一个 div(带有 id='a'),我不希望它有背景图像。
我必须给它什么 css 规则?
回答by AnthonyWJones
Try:
尝试:
div#a {
background-image:none
}
回答by Ruud
div#a {
background-image: none;
}
回答by M4N
div#a {
background-image: none !important;
}
Although the "!important" might not be necessary, because "div#a" has a higher specificity than just "div".
尽管“!important”可能不是必需的,因为“div#a”比“div”具有更高的特异性。
回答by MatthewPearson
div#a {
background-image: url('../images/spacer.png');
background-image: none !important;
}
I use a transparent spacer image in addition to the rule to remove the background image because IE6 seems to ignore the background-image: none
even though it is marked !important
.
除了删除背景图像的规则外,我还使用透明间隔图像,因为 IE6 似乎忽略了background-image: none
即使它被标记为!important
.
回答by ItsMe
Since in css3 one might set multiple background images setting "none" will only create a new layer and hide nothing.
由于在 css3 中可能会设置多个背景图像,设置“无”只会创建一个新层并且不隐藏任何内容。
http://www.css3.info/preview/multiple-backgrounds/http://www.w3.org/TR/css3-background/#backgrounds
http://www.css3.info/preview/multiple-backgrounds/ http://www.w3.org/TR/css3-background/#backgrounds
I have not found a solution yet...
我还没有找到解决方案...
回答by buTs
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%);
for older browsers.. if you have defined css in some framewokrk.css like select2.css in IE9 background-image: -webkit-gradient etc. and you want it via another .css rewrite with "background-image: none !important" not works. I used same color to color gradient like page background color.
对于较旧的浏览器.. 如果您在某些 framewokrk.css 中定义了 css,例如 IE9 背景图像中的 select2.css:-webkit-gradient 等,并且您希望通过另一个 .css 重写“background-image: none !important”不工作。我使用相同的颜色来为页面背景颜色等渐变着色。
回答by Micha? Szymański
When background-image: none !important;
have no effect.
You can use:
什么时候background-image: none !important;
没有效果。您可以使用:
background-size: 0 !important;
回答by Justin Love
If your div rule is just div {...}
, then #a {...}
will be sufficient. If it is more complicated, you need a "more specific" selector, as defined by the CSS specification on specificity. (#a being more specific than div is just single aspect in the algorithm.)
如果您的 div 规则只是div {...}
,那么#a {...}
就足够了。如果它更复杂,您需要一个“更具体”的选择器,如CSS 规范中关于 specificity 的定义。(#a 比 div 更具体只是算法中的一个方面。)
回答by circusdei
Replace the rule you have with the following:
将您拥有的规则替换为以下内容:
div:not(#a) { // add your bg image here //}
回答by Ben Hall
Doesn't this work:
这不工作:
.clear-background{
background-image: none;
}
Might have problems on older browsers...
可能在旧浏览器上有问题...