技术笔记

前端学习之背景图错位

现象如下图:这里的想法是不将背景图片放到body上,而是body充满屏幕,div(这个div作为整个内容容器)充满body,然后div背景图充满div。

前端学习之背景图错位

现象

现象如下图: 亲刷新试试 这里的想法是不将背景图片放到body上,而是body充满屏幕,div(这个div作为整个内容容器)充满body,然后div背景图充满div。

分析

代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>csstest</title>
    <style>
        html{
            height:100%;
        }
        body{
            background-color: red;
            height: 100%;
            margin: 0px;
            padding: 0px;
            overflow: hidden;
        }

        #container{
            background: url(image/dota2Index.jpg);
            background-size: cover;
            background-repeat: no-repeat;
            color: white;
            height: 100%;
            font-size: xx-large;
            padding: 0px;
            margin: 0px;
            width: 100%;
        /*    position: absolute;
            top: 0;
            left: 0;*/
        }

        #container p{
            text-align: center;
        }
    </style>
</head>
<body>
    <div id="container">
       <p id="welcomeWord"> welcome to dota2</p>
    </div>
</body>
</html>

解决方法

将稳重注释掉的地方恢复。