how to set footer at the bottom when there is no content

后端 未结 3 1643
暖寄归人
暖寄归人 2021-01-29 06:13



        
3条回答
  •  逝去的感伤
    2021-01-29 07:05

    You have three options from which I would suggest using flex-box.

    1. position: fixed

    footer {
        position: fixed;
        left: 0;
        bottom: 0;
        right: 0;
    }
    

    2. Flex-box

    HTML

    
        
            

    CSS

    html {
        height: 100%;
    }
    
    body {
        display: flex;
        flex-direction: column;
        min-height: 100vh;
    }
    
    main {
        flex-grow: 1;
    }
    

    Demo: https://codepen.io/marcobiedermann/pen/XpoarE

    3. Table

    HTML

    
        
            

    CSS

    html {
        height: 100%;
    }
    
    body {
        display: table;
        min-height: 100vh;
    }
    
    main: {
        height: 100%;
    }
    
    footer {
        display: table-row;
        height: 1px;
    }
    

    Demo: https://codepen.io/marcobiedermann/pen/jImsc

提交回复
热议问题