Make body have 100% of the browser height

后端 未结 21 1337
离开以前
离开以前 2020-11-22 00:26

I want to make body have 100% of the browser height. Can I do that using CSS?

I tried setting height: 100%, but it doesn\'t work.

I want to set

21条回答
  •  北海茫月
    2020-11-22 00:35

    Try setting the height of the html element to 100% as well.

    html, 
    body {
        height: 100%;
    }
    

    Body looks to its parent (HTML) for how to scale the dynamic property, so the HTML element needs to have its height set as well.

    However the content of body will probably need to change dynamically. Setting min-height to 100% will accomplish this goal.

    html {
      height: 100%;
    }
    body {
      min-height: 100%;
    }
    

提交回复
热议问题