Create a scrolling div between two fixed div elements

与世无争的帅哥 提交于 2019-12-02 12:37:29

Simply set the height of the consecutive elements to equal 100% and set your content DIV to scroll on the Y-axis:

<header>
    <h1>Sandwich Layout</h1>
</header>
<div id="main" role="main">

</div>
<footer>
    Footer stuff here
</footer>

html,
body { height: 100%; margin: 0; padding: 0; } /* This is important */

header,
footer { background: #ccc; height:20%; }

#main { height: 60%; overflow-y:scroll; }

Fiddle: http://jsfiddle.net/kboucher/3E8Gg/

If you set your header and footer divs to fixed, you can make a main div for your content which will scroll the way you want it to.

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