css固定footer到瀏覽器底部的方法


<html>
<head></head>
<body>
    <div class="page-wrapper">
        <div class="page-content">內容部分</div>
    </div>
    <footer class="footer">這里是頁面底部</footer>
</body>    
</html>

//css
html, body{
  height: 100%;
}
footer{
  height: 50px;
  line-height: 50px;
  background-color: #62f1c3;
  text-align: center;
}

 

1、position: fixed

//css
.page-wrapper{
  padding-bottom: 50px;
}
.footer{
  position: fixed;
  width: 100%;
  bottom: 0;
}

2、footer前的元素使用負margin-bottom

.page-wrapper{
    height: 100%;    
    padding-bottom: 50px;
    margin-bottom: -50px;
    overflow-y: auto;
}

 3、footer元素使用負margin-top

 
         
 
.page-wrapper{
height: 100%;
padding
-bottom: 50px; overflow-y: auto; } .footer{ margin-top: -50px; }

4、使用calc()計算內容部分的高度

.page-wrapper{
    height: calc(100% - 50px);
    overflow-y: auto;
}

5、使用flex-box布局

body{
   display: flex;
    flex-direction: column;
}

.page-wrapper{
    flex: 1 1 auto;
overflow-y: auto; } .footer{ flex:
0 0 auto; }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM