CSS: fixed to bottom and centered

前端 未结 9 1310
南笙
南笙 2020-11-28 04:33

I need my footer to be fixed to the bottom of the page and to center it. The contents of the footer may change at all time so I can\'t just center it via margin-left: xxpx;

9条回答
  •  Happy的楠姐
    2020-11-28 04:46

    here is an example using css grid.

    html, body{
        height: 100%;
        width: 100%;
    }
    .container{
        height: 100%;
        display:grid;
        /*we divide the page into 3 parts*/
        grid-template-rows: 20px auto  30px;
        text-align: center;   /*this is to center the element*/ 
        
    }
    
    .container .footer{
        grid-row: 3;   /*the footer will occupy the last row*/
        display: inline-block;
        margin-top: -20px;
    }
    
    
    
        
        
        Document
    
    
        

    you can use css grid:a concrete example

提交回复
热议问题