【发布时间】:2015-04-27 19:04:34
【问题描述】:
在 CSS 中,我使用 gif 作为背景图片:
background: url(http://*URL of gif*) no-repeat 50% 50%;
但根据屏幕尺寸,我仍然可以稍微看到该图像背后的背景(它是白色的)。如何更改该图像背后的颜色?我想把它改成黑色。
【问题讨论】:
标签: css background-image background-color
在 CSS 中,我使用 gif 作为背景图片:
background: url(http://*URL of gif*) no-repeat 50% 50%;
但根据屏幕尺寸,我仍然可以稍微看到该图像背后的背景(它是白色的)。如何更改该图像背后的颜色?我想把它改成黑色。
【问题讨论】:
标签: css background-image background-color
只需在声明中包含背景颜色
background: yourcolor url(http://*URL of gif*) no-repeat 50% 50%;
【讨论】:
背景速记属性由其他八个属性组成:
background-image
background-position
background-size
background-repeat
background-attachment
background-origin
background-clip
background-color
因此,速记属性可以写成:
background : <background-image> <background-position> <background-size> <background-repeat> <background-attachment> <background-origin> <background-clip> <background-color>
在你的情况下,你会使用这个(因为你想要黑色):
background: url(http://*URL of gif*) no-repeat 50% 50% black;
请看下面的例子:
div {
background :url('http://i.stack.imgur.com/SZHzX.jpg') top center no-repeat black;
padding: 10px;
width:100%;
height:300px;
}
<div></div>
希望对你有帮助!!!
【讨论】:
你用的是背景的简写,你可以写成
background-image :
background-color :
background-size :
background-repeat :
【讨论】:
无法更改设置为背景的图像“背后”的背景,但这也不是您想要的。
背景速记还使您可以设置颜色值。这将在图像未覆盖背景的任何地方可见。
所以只需使用:
background: url(http://url) 50% 50% no-repeat #000;
【讨论】: