繁体   English   中英

水平滚动,高度固定在100%

[英]horizontal scroll with height fixed on 100%

这是我创建的http://jsfiddle.net/ZygnV/

    <html>
    <head>
        <style type="text/css">
            html, body{
                margin: 0;
                padding: 0;
                height: 100%; 
            }
            .main-content-wrapper{
                height: 100%;
                overflow-y: hidden; 
                white-space: nowrap;
            }
            .main-sidebar{
                display: inline-block;
                height: 100%;
                width: 220px;
                background-color: rgb(0,0,0);
            }
            .main-content{
                display: inline-block;
                height: 100%;
                width: 10000px;
            }
        </style>
    </head>
    <body>
        <div class="main-content-wrapper">
            <nav class="main-sidebar">
            </nav><section id="main-content" class="main-content">

            </section>
        </div>
</body>

问题是垂直滚动太小:我想没有它。

为什么是这个小虫子? 我该如何解决? 我本来想将overflow-y:hidden设置为隐藏的,但我认为这不是最好的解决方案:如果我要设置最小高度,然后显示滚动条,它将始终处于隐藏状态(除非我使用js脚本操作)

首先不应该有垂直滚动。

其背后的原因是navsectiondisplay: inline-block ,因此代码格式中的空格会影响布局。 解决问题的方法多种 ,其中一种方法是设置font-size: 0 .main-content-wrapper上设置font-size: 0.main-content-wrapper.main-content-wrapper所需的font-size

JSFiddle

另外,您可以使用其他方法放置侧边栏和内容,在这种情况下, 灵活框的效果非常好。

这可以帮助您

    .main-content {
    display: inline-block;
    height: 100%;
    position: absolute;
    width: 10000px;
   }
   .main-sidebar {
    background-color: #000000;
    display: inline-block;
    height: 100%;
    position: absolute;
    width: 220px;
    }

添加overflow:hidden到主div

.main-content-wrapper{
            height: 100%;
            white-space: nowrap;
            overflow:hidden
        }

DEMO

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM