Make body have 100% of the browser height

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

    I would use this

    html, body{
          background: #E73;
          min-height: 100%;
          min-height: 100vh;
          overflow: auto; // <- this is needed when you resize the screen
        }
    
        
        
    

    The browser will use min-height: 100vh and if somehow the browser is a little older the min-height: 100% will be the fallback.

    The overflow: auto is necessary if you want the body and html to expand their height when you resize the screen (to a mobile size for example)

提交回复
热议问题