CSS How to set div height 100% minus nPx

前端 未结 11 1358
自闭症患者
自闭症患者 2020-12-02 04:17

I have a wrapper div which contans 2 divs next to each other. Above this container I have a div that contains my header. The wrapper div must be 100% minus the height of the

11条回答
  •  南笙
    南笙 (楼主)
    2020-12-02 05:18

    I haven't seen anything like this posted yet, but I thought I'd put it out there.

    Header
    Content

    Then CSS:

    body, html {
        height: 100%;
        margin: 0;
        padding: 0;
    }
    
    .main {
        height: 100%;
        padding-top: 50px;
        box-sizing: border-box;
    }
    
    header {
        height: 50px;
        margin-top: -50px;
        width: 100%;
        background-color: #5078a5;
    }
    
    .content {
        height: 100%;
        background-color: #999999;
    }
    

    Here is a working jsfiddle

    Note: I have no idea what the browser compatability is for this. I was just playing around with alternate solutions and this seemed to work well.

提交回复
热议问题