![](/img/trans.png)
[英]How do I stick my footer to the bottom when there is less content in my html page
[英]How to stick footer always to the bottom of the page if the content is very less?
即使我重新調整頁面大小,頁腳也應保留在底部。 就我而言,當我調整頁面高度的大小時,頁腳與內容重疊。
.body{ background: #00b7ea; /* Old browsers */ font-family:Arial, Helvetica, sans-serif; font-size:85%; height: 100%; } .container{ min-height:100%; position: relative; } .formContainer{ width:30%; height: 100px; background-color:#fff; margin:auto; padding-top: 0; border-radius:5px; box-shadow:5px 5px 55px #9999; padding-bottom:60px; } .footer{ position:absolute; width:100%; bottom:0; height:60px; background-color:#333; }
<body class="body"> <header class="header"> </header> <div class="container"> <div class="formContainer"> </div> <footer class="footer"> </footer> </div> </body>
您需要的是粘性頁腳,有兩種方法可以實現它。
嘗試這個
.footer{
position:fixed;
width:100%;
bottom:0;
height:60px;
background-color:#333;
}
嘗試這個。 謝謝
CSS
.body{
background: #00b7ea; /* Old browsers */
font-family:Arial, Helvetica, sans-serif;
font-size:85%;
height: 100%;
}
.container{
height:90%;
background-color:#fff;
}
.formContainer{
width:100%;
height: 100px;
margin:auto;
padding-top: 0;
border-radius:5px;
box-shadow:5px 5px 55px #9999;
padding-bottom:60px;
}
.footer{
width:100%;
bottom:0;
height:5%;
background-color:#333;
}
HTML
<body class="body">
<header class="header">
</header>
<div class="container">
<div class="formContainer">
</div>
</div>
<footer class="footer">test
</footer>
</body>
我遇到了同樣的問題,我使用了以下代碼:
<script>
var top = $(document).height() - $("footer.main-footer").height() ;
$("footer.main-footer").css('top' , top);
</script>
將.main-footer更改為您的頁腳類。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.