前端 - CSS里的overflow问题

查看:80
本文介绍了前端 - 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就会隐藏啊

这篇关于前端 - CSS里的overflow问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆