頁腳動態貼在底部須要知足如下兩個條件:css
<body> <header>header</header> <main>content</main> <footer>footer</footer> </body>
html{height:100%;} body{min-height:100%;margin:0;padding:0;position:relative;} header{background-color: #ffe4c4;} main{padding-bottom:100px;background-color: #bdb76b;} footer{position:absolute;bottom:0;width:100%;height:100px;background-color: #ffc0cb;}
<body> <div class="container"> <header>header</header> <main>main content</main> </div> <footer>footer</footer> </body>
html,body{height:100%;margin:0;padding:0;} .container{min-height:100%;} header{background-color: #ffe4c4;} main{padding-bottom:100px;background-color: #bdb76b;}/* main的padding-bottom值要等於或大於footer的height值 */ footer{height:100px;margin-top:-100px;background-color: #ffc0cb;}
<div class="wrapper">
<div class="header">頭部</div>
<div class="main">
<div class="box sidebar">左側欄</div>
<div class="box content">主體內容</div>
<div class="box sidebar">有側欄</div>
</div>
<div class="footer">頁腳底部</div>
</div>body {
background: @beige;
color: black;
}
.wrapper {
height: 100%;
display: table;
width: 100%;
text-align: center;
}
.header {
display: table-row;
height: 1px;
background: @yellow;
}
.main {
height: 100%;
display: table;
width: 100%;
}
.box {
display: table-cell;
}
.sidebar {
width: 100px;
background: @orange;
}
.footer {
display: table-row;
height:1px;
background: @green;
color: @beige;
}
@orange: #BD4932;
@yellow: #FFD34E;
@green: #105B63;
@beige: #FFFAD5;