【问题标题】:Changing the colour of background behind image css更改图像css后面的背景颜色
【发布时间】:2015-04-27 19:04:34
【问题描述】:

在 CSS 中,我使用 gif 作为背景图片:

background: url(http://*URL of gif*) no-repeat 50% 50%;

但根据屏幕尺寸,我仍然可以稍微看到该图像背后的背景(它是白色的)。如何更改该图像背后的颜色?我想把它改成黑色。

【问题讨论】:

    标签: css background-image background-color


    【解决方案1】:

    只需在声明中包含背景颜色

    background: yourcolor url(http://*URL of gif*) no-repeat 50% 50%;
    

    【讨论】:

    • 嗨,我们可以改变'url'内的png图像的颜色
    【解决方案2】:

    背景速记属性由其他八个属性组成:

    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;
    
    }
    &lt;div&gt;&lt;/div&gt;

    希望对你有帮助!!!

    【讨论】:

      【解决方案3】:

      你用的是背景的简写,你可以写成

      background-image : background-color : background-size : background-repeat :

      【讨论】:

        【解决方案4】:

        无法更改设置为背景的图像“背后”的背景,但这也不是您想要的。

        背景速记还使您可以设置颜色值。这将在图像未覆盖背景的任何地方可见。

        所以只需使用:

        background: url(http://url) 50% 50% no-repeat #000;
        

        【讨论】:

          猜你喜欢
          • 2016-12-13
          • 2019-04-22
          • 2014-04-26
          • 2012-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-11-23
          • 1970-01-01
          相关资源
          最近更新 更多