首页 > CSS里的overflow问题

CSS里的overflow问题

写一个页面的时候,发现像这样:

html,body{
    overflow:hidden
}

给html和body加一个overflow:hidden,然后右边的滚动条就消失了,为什么会这样呢?哪位大牛给我解答下呗,谢谢啦,嘻嘻(∩_∩)

完整代码:

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style type="text/css">
        *{
            margin: 0;
            padding: 0;
        }
        html,body{
            height: 100%;
        }
        .section,.sections{
            height: 100%;
        }

        .container{
            height: 100%;
            overflow: hidden;
        }
        #section0,
        #section1,
        #section2,
        #section3{
            background-color: #000;
            background-size: cover;
            background-position: 50% 50%;
            text-align: center;
            color: white;
        }
        #section0{
            background-image: url(images/1.jpg);
        }
        #section1{
            background-image: url(images/2.jpg);
        }
        #section2{
            background-image: url(images/3.jpg);
        }
        #section3{
            background-image: url(images/4.jpg);
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="sections">
            <div class="section" id="section0">
                <h3>this is the page</h3>
            </div>
            <div class="section" id="section1">
                <h3>this is the page</h3>
            </div>
            <div class="section" id="section2">
                <h3>this is the page</h3>
            </div>
            <div class="section" id="section3">
                <h3>this is the page</h3>
            </div>
        </div>
    </div>
</body>
</html>

overflow:hidden的作用是隐藏溢出,超过一定高度的内容会被隐藏掉,后面没有内容了,滚动条也就消失了。


overflow本来就是设置元素溢出时的状态;设置为hidden就会隐藏啊


overflow 属性规定当内容溢出元素框时发生的事情。
参考这里传送门

【热门文章】
【热门文章】