Horizontal scrollbar only appearing at bottom of page

一世执手 提交于 2020-05-10 09:06:14

问题


I have a page with the following HTML structure...

<html>
    ...
    <body>
        <div class="wrapper">
        ...
        </div>
    </body>
</html>

The .wrapper is being set at min-width: 1100px for reasons I won't go into. Therefore when the browser is resized to less than 1100px I want a horizontal scrollbar to appear.

My CSS is as follows:

html {
    overflow-x: scroll;
    height: 100%;
}

body {
    overflow: auto;
}

.wrapper {
    min-width: 1100px;
    margin: 0 auto;
}

For some reason the only horizontal scrollbar showing is one when you've scrolled vertically down to the bottom of the page, and it appears sort of "within" the main browser frame, above the main browser horizontal scroll area. I want the main horizontal scrollbar of the window to be the one that is available.

Here is a diagram of my problem: http://oi62.tinypic.com/r06m1z.jpg

And a codepen: http://codepen.io/anon/pen/ocxvs

Thanks in advance for any help!


回答1:


Its because your document (body) isnt stretched to the full height of the viewport (html), you need to assign height:100vh, also remove your overflow settings so you dont get 2 scrollbars appearing (one on body one on html).

Simply change your CSS to:

html,body{
  height:100vh;
  width:100vw;
  margin: 0;
  padding: 0;
}


来源:https://stackoverflow.com/questions/25200424/horizontal-scrollbar-only-appearing-at-bottom-of-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!