scroll bar on div with overflow:auto and percentage height

前端 未结 1 1025
一个人的身影
一个人的身影 2021-01-12 11:27

Is it possible to create a div that adjusts to the size of the browser and is also scrollable? I want to use overflow:auto on the div and percentage height of <

相关标签:
1条回答
  • 2021-01-12 11:54

    In answer to your question, yes overflow:auto will work, but you will need height: 100% on the HTML tag as well:

    html,body {    
        height:100%;
        margin: 0;
    }
    #header {
        height: 100%;
    }
    #content {
        height: 100%;
        overflow: auto;
    }
    

    The way your markup is structured though will produce two divs both the same height as the viewport one on top of the other. Is that what you intended?

    If so here is a jsFiddle that illustrates your example. I've tweaked the markup and added additional content so that the content div overflows as you require.

    http://jsfiddle.net/chrissp26/WsNjm/

    0 讨论(0)
提交回复
热议问题