How can I stretch a div to 100% page height?

前端 未结 10 1276
一生所求
一生所求 2021-02-06 17:56

    
        

        

    
        
相关标签:
10条回答
  • 2021-02-06 18:42

    You should set 100% height for the body and it should do:

    body {
    ...
    height:100%;
    ...
    }
    
    0 讨论(0)
  • 2021-02-06 18:47

    Try (it should work in most browsers):

    .100PercentHeight, html, body {
        height : auto !important; /* Ignored by Internet Explorer, applied everywhere else. */
        height : 100%;            /* Internet Explorer treats as min-height. */
        min-height : 100%;        /* Internet Explorer ignores this. */
    }
    
    0 讨论(0)
  • 2021-02-06 18:52

    This should work:

    <style type="text/css">
        html, body, .100PercentHeight {
            height: 100%;
            margin: -10px 0px 0px -10px;
        }
    </style>
    

    However, you may want to add a background colour or border to make sure it works, else you won't be able to see it properly.

    0 讨论(0)
  • 2021-02-06 18:56

    Use:

    {
        position: absolute;
        top: 0px;
        bottom: 0px;
        padding: 0px;
        margin: 0px;
    }
    

    This way, it will be centered and cover the page if it is longer than one browser view long.

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