请教一个web布局问题?

描述一下,对于页面,

内容少得不足以产生滚动条的时候,footer落在最底部面,
当内容变多,页面产生滚动条时,footer要处于内容的最后,即滚动到最底部才能看见

我知道一种是使用 负值margin-top 和 正值padding-bottom 的方法,但是感觉不够灵活..

请问有没有什么好的实现方法?

https://img.mukewang.com/5c1365890001ae1306920538.jpg

这是我答案:
纯css
因为我主要用在移动端 应该可以兼容吧....
https://jsfiddle.net/BoomBang...

慕容森
浏览 405回答 1
1回答

慕姐4208626

这种东西就在于思路:<!DOCTYPE html><html><head>&nbsp; &nbsp; <meta charset="utf-8">&nbsp; &nbsp; <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/>&nbsp; &nbsp; <title></title></head><body>&nbsp; &nbsp; <style>&nbsp; &nbsp; body{&nbsp; &nbsp; &nbsp; &nbsp; margin: 0;&nbsp; &nbsp; }&nbsp; &nbsp; html,&nbsp; &nbsp; body,&nbsp; &nbsp; .wrap {&nbsp; &nbsp; &nbsp; &nbsp; height: 100%;&nbsp; &nbsp; }&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; .content {&nbsp; &nbsp; &nbsp; &nbsp; min-height: 100%;&nbsp; &nbsp; }&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; footer {&nbsp; &nbsp; &nbsp; &nbsp; height:50px;&nbsp; &nbsp; &nbsp; &nbsp; background-color: #0cc;&nbsp; &nbsp; &nbsp; &nbsp; margin-top: -50px;&nbsp; &nbsp; }&nbsp; &nbsp; </style>&nbsp; &nbsp; <div class="wrap">&nbsp; &nbsp; &nbsp; &nbsp; <div class="content">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div>内容区域</div>&nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; <footer>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 底部&nbsp; &nbsp; &nbsp; &nbsp; </footer>&nbsp; &nbsp; </div></body></html>效果图:
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript