Make body have 100% of the browser height

后端 未结 21 1634
离开以前
离开以前 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

    If you have a background image then you will want to set this instead:

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

    This ensures that your body tag is allowed to continue growing when the content is taller than the viewport and that the background image continues to repeat/scroll/whatever when you start scrolling down.

    Remember if you have to support IE6 you will need to find a way to wedge in height:100% for body, IE6 treats height like min-height anyway.

提交回复
热议问题