How can an html element fill out 100% of the remaining screen height, using css only?

后端 未结 17 1817
名媛妹妹
名媛妹妹 2020-12-22 16:13

I have a header element and a content element:

#header
#content

I want the header to be of fixed height and the content to fill up all the

17条回答
  •  自闭症患者
    2020-12-22 17:12

    forget all the answers, this line of CSS worked for me in 2 seconds :

    height:100vh;
    

    1vh = 1% of browser screen height

    source

    For responsive layout scaling, you might want to use :

    min-height: 100vh
    

    [update november 2018] As mentionned in the comments, using the min-height might avoid having issues on reponsive designs

    [update april 2018] As mentioned in the comments, back in 2011 when the question was asked, not all browsers supported the viewport units. The other answers were the solutions back then -- vmax is still not supported in IE, so this might not be the best solution for all yet.

提交回复
热议问题