Two vertical divs within a 100% height div

前端 未结 3 939
灰色年华
灰色年华 2021-01-19 17:41

Sorry for my bad english, hope you will understand my issue.

I\'m turning my head around a problem that I know I\'ve been solving once before. The issue is that I ne

相关标签:
3条回答
  • 2021-01-19 18:18

    Use position: relative combined with position: absolute.

    Live Demo

    Get rid of these last two lines:

    div#iHeader { height:50px; background:#009900; }
    div#iWrapper  { height:100%; padding-top:-50px; padding-bottom:-150px; overflow:auto; }
    

    Replace them with:

    div#list {
        position: relative
    }
    div#iHeader {
        height:50px; background:#009900;
    
        width: 100%;
        position: absolute;
        top: 0;
        left: 0
    }
    div#iWrapper { 
        overflow:auto;
    
        width: 100%;
        position: absolute;
        top: 50px;
        left: 0;
        bottom: 0
    }
    
    0 讨论(0)
  • 2021-01-19 18:21

    here's a slightly different way to do it so you don't need to use the top and bottom co-ordinates together - that way it can be made to work in IE7 too

    (this does involve putting IE6/7 into Quirks mode though, but if it's any use see the comment before the Doctype how to do that)

    JSBIN - IE7 compatible version

    This is the quite similar to thirtydots, in that it uses a mixture of relative and absolute, but this method uses the border-box box-sizing model so space can be created by padding and still maintain the use of height: 100%;

    0 讨论(0)
  • 2021-01-19 18:36

    Delete that 1k Height div, and make this iWrapper ver flow auto. So change this:

    <div id="iWrapper">
      <div style="height:1000px;">
        test test
      </div>
    </div>
    

    to this:

    <div id="iWrapper" style="overflow: auto;">
        test test
    </div>
    

    Or add it to your stylesheet.

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