How can I make DIV 100% height of browser without vertical scrolling of header

前端 未结 6 2320
遇见更好的自我
遇见更好的自我 2021-01-05 08:32

Both the left and right panels have a height of 100%, but since the Header div takes up X amount of space, there is some vertical scrolling in the window th

6条回答
  •  日久生厌
    2021-01-05 08:56

    You can use absolute positioning if you want to have it 100% height always. And then use scroll bars if required inside the leftpanel or the rightpanel.

    Example: http://jsfiddle.net/G7unG/2/

    html, body{
        height: 100%;
        margin: 0;
    }
    .header{
        background: #333;
        padding: 15px;
        text-align:center;
        font-size: 18px;
        font-family: sans-serif;
        color: #FFF;
        height: 22px;
    }
    .leftpanel, .rightpanel{
        top: 52px;
        bottom: 0;
        position: absolute;
    }
    .leftpanel{
        width: 70%;
        left: 0;
        background: #CCC;
    }
    .rightpanel{
        width: 30%;
        right: 0;
        background: #666;
    }
    

    Solution 2 - use fixed percentages for height: http://jsfiddle.net/G7unG/4/

    html, body{
        height: 100%;
        margin: 0;
    }
    .header{
        background: #333;
        padding: 15px;
        text-align:center;
        font-size: 18px;
        font-family: sans-serif;
        color: #FFF;
        height: 30%;
        box-sizing: border-box;
    }
    .leftpanel, .rightpanel{
        height: 70%;
        float: left;
    }
    .leftpanel{
        width: 70%;
        left: 0;
        background: #CCC;
    }
    .rightpanel{
        width: 30%;
        float: right;
        background: #666;
    }
    

提交回复
热议问题