HTML完整背景图像不能与bootstrap一起使用

时间:2017-06-03 08:50:26

标签: twitter-bootstrap css3

目前的代码是

<html><head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>Full Page Background Image</title>

    <style>
        * { margin: 0; padding: 0; }

        html { 
            background: url(./images/bg.jpg) no-repeat center center fixed !important; 
            -webkit-background-size: cover;
            -moz-background-size: cover;
            -o-background-size: cover;
            background-size: cover;
        }


    </style>
</head>

<body>

</body>
</html>

它显示全屏背景图像。但是,我试图添加bootstrap css,背景图片不见了。

<html><head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>Full Page Background Image</title>
    <link href="./bootstrap/css/bootstrap.css" rel="stylesheet">
    <script src="./js/jquery.min.js"></script>
    <script src="./bootstrap/js/bootstrap.min.js"></script>
    <style>
        * { margin: 0; padding: 0; }

        html { 
            background: url(./images/bg.jpg) no-repeat center center fixed; 
            -webkit-background-size: cover ;
            -moz-background-size: cover ;
            -o-background-size: cover ;
            background-size: cover;
        }


    </style>
</head>

<body>

</body>
</html>

我想知道为什么以及如何解决这个问题?

2 个答案:

答案 0 :(得分:2)

使用body而非html用于CSS

<html><head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>Full Page Background Image</title>
    <link href="./bootstrap/css/bootstrap.css" rel="stylesheet">
    <script src="./js/jquery.min.js"></script>
    <script src="./bootstrap/js/bootstrap.min.js"></script>
    <style>
        * { margin: 0; padding: 0; }

        body { 
            background: url(./images/bg.jpg) no-repeat center center fixed; 
            -webkit-background-size: cover ;
            -moz-background-size: cover ;
            -o-background-size: cover ;
            background-size: cover;
        }


    </style>
</head>

<body>

</body>
</html>

答案 1 :(得分:0)

添加

后它正在工作
body {
 background: none;
}