为什么完整的背景图像适用于身体而不是CSS中的html?

时间:2017-11-08 16:59:58

标签: html css

我在CSS中执行了以下操作,但它没有更改网页:

html {

                background:url("image.jpg") no-repeat center center fixed;
                -webkit-background-size: cover;
                -moz-background-size: cover;
                -o-background-size: cover;
                background-size: cover;
            }

但后来我做了以下代码,背景改变了我想要的方式:

body {
                margin:0;
                padding:0;
                background:url("image.jpg") no-repeat center center fixed;
                -webkit-background-size: cover;
                -moz-background-size: cover;
                -o-background-size: cover;
                background-size: cover;
            }

为什么html调用不会更新它,但身体会更新它是没有意义的。

除了我正在使用的Bootstrap框架外,其余代码都是空白的。

1 个答案:

答案 0 :(得分:0)

  

除了我使用

的Bootstrap框架之外,其余代码都是空白的

......那是你的问题。

Bootstrap CSS在body元素上设置背景颜色。

body{font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:14px;line-height:1.42857143;color:#333;background-color:#fff}

- source

这将覆盖您应用于HTML元素的任何背景。

设置body { background: transparent }会覆盖它。