How to force child div to be 100% of parent div's height without specifying parent's height?

前端 未结 26 1651
刺人心
刺人心 2020-11-22 06:52

I have a site with the following structure:

<
相关标签:
26条回答
  • 2020-11-22 07:47

    This trick does work: Adding a final element in your section of HTML with a style of clear:both;

        <div style="clear:both;"></div>
    

    Everything before that will be included in the height.

    0 讨论(0)
  • 2020-11-22 07:48

    height : <percent> will only work if you have all parent nodes with specified percent height with a fixed height in pixels, ems, etc. on top level. That way, the height will cascade down to your element.

    You can specify 100% to html and body elements as @Travis stated earlier to have the page height cascading down to your nodes.

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