CSS:页脚紧贴底部
生活随笔
收集整理的這篇文章主要介紹了
CSS:页脚紧贴底部
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2019獨角獸企業重金招聘Python工程師標準>>>
我的練習來源于《CSS揭秘》這本書第7章-41緊貼底部的頁腳這部分內容以及書中提到的鏈接。
方案一
描述:以下方案簡單、干凈、現代并且沒有hack,適用于IE8+, Chrome, Firefox, Opera等瀏覽器;不需要使用任何標簽包裹,因為它是基于可變的body高度;這個解決方案誕生于2012年初,今天也許應該使用更好的方案比如flexbox。
<!DOCTYPE html> <html> <head><meta charset="utf-8" /><title>css緊貼底部的頁腳</title> </head> <style type="text/css"> /*footer緊貼底部的主要代碼*/ html{position: relative;min-height: 100%; } body{margin: 0 0 100px; } footer{position: absolute;left: 0;bottom: 0;height: 50px;width: 100%;background-color: green;/*設置顏色方便查看footer位置*/ } /*調整內容的高度以查看footer緊貼底部的效果*/ .content{height: 100px; } </style> <body><div class="content"></div><footer></footer> </body> </html>?
方案二
描述:使用display的flex屬性
<!DOCTYPE html> <html> <head><meta charset="utf-8" /><title>css緊貼底部的頁腳</title> </head> <style type="text/css"> /*footer緊貼底部的主要代碼*/ body{margin: 0;display: flex;min-height: 100vh;flex-direction: column; } footer{height: 50px;width: 100%;background-color: green;/*設置顏色方便查看footer位置*/ } .content{flex: 1; } </style> <body><div class="content"></div><footer></footer> </body> </html>?
方案三
描述:使用?calc()方法
<!DOCTYPE html> <html> <head><meta charset="utf-8" /><title>css緊貼底部的頁腳</title> </head> <style type="text/css"> /*footer緊貼底部的主要代碼*/ body{margin: 0; } footer{height: 50px;width: 100%;background-color: green;/*設置顏色方便查看footer位置*/ } .content{min-height: calc(100vh - 50px); } </style> <body><div class="content"><div style="height:1000px;">這個div用來撐高度的</div></div><footer></footer> </body> </html>(未完待續……)
參考:
轉載于:https://my.oschina.net/u/1165991/blog/746765
總結
以上是生活随笔為你收集整理的CSS:页脚紧贴底部的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Keras 深度学习框架中文文档
- 下一篇: 如何使用CSS实现居中