绝对底部(保持footer在页面最底部) 发表于 2019-04-08 | 绝对底部(保持footer在页面最底部)demo 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>绝对底部(保持footer在页面最底部)</title> <script src="https://cdn.bootcss.com/vue/2.5.17-beta.0/vue.min.js"></script></head><body><style> * { margin: 0; padding: 0; } body { height: 100vh; } #wrap { height: auto; min-height: 100%; } #main { padding-bottom: 150px; /* 和footer相同的高度 */ } #footer { margin-top: -150px; /* footer高度的负值 */ height: 150px; background: #0c8ed9 }</style><div id="wrap"> <div id="main"> <div id="app" style="padding: 40px;"> <button @click="toggle">切换数据长度 {{length}}</button> <ul> <li v-for="i in length">数据</li> </ul> </div> </div></div><div id="footer">底部</div> <!--底部和外层同级--></body><script> const lenArr = [20,400] new Vue({ el: '#app', data:{ length: lenArr[0] }, methods:{ toggle(){ this.length = this.length === lenArr[0]?lenArr[1]:lenArr[0] } } })</script></html>