Make body have 100% of the browser height

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

    You can also use JS if needed

    var winHeight = window.innerHeight    || 
    document.documentElement.clientHeight || 
    document.body.clientHeight;
    
    var pageHeight = $('body').height();
    if (pageHeight < winHeight) {
        $('.main-content,').css('min-height',winHeight)
    }
    

提交回复
热议问题