Relative div height

后端 未结 6 1792
自闭症患者
自闭症患者 2021-02-19 06:07

I want to split up the view in four parts. A header at the top, using full page width and fixed height.

The remaining page is split up in two blocks of the same height,

6条回答
  •  遇见更好的自我
    2021-02-19 06:10

    When you set a percentage height on an element who's parent elements don't have heights set, the parent elements have a default

    height: auto;
    

    You are asking the browser to calculate a height from an undefined value. Since that would equal a null-value, the result is that the browser does nothing with the height of child elements.

    Besides using a JavaScript solution you could use this deadly easy table method:

    #parent3 {
        display: table;
        width: 100%;
    }
    
    #parent3 .between {
        display: table-row;
    }
    
    #parent3 .child {
        display: table-cell;
    }
    

    Preview on http://jsbin.com/IkEqAfi/1

    • Example 1: Not working
    • Example 2: Fix height
    • Example 3: Table method

    But: Bare in mind, that the table method only works properly in all modern Browsers and the Internet Explorer 8 and higher. As Fallback you could use JavaScript.

提交回复
热议问题