Home | Search | About All | Contact me | Online:8
Font + | Font -
  • Notice News
  • Css style Teaching
  • JavaScript Skills
  • Web design
  • Cool site
  • Free board
  • To Candy
OECSPACE - Css style 教學「實現完美的 footer 底部排版」
  • 樣式表簡介
  • 基礎運用
  • 基本樣式
  • 實例運用
  • CSS技術運用
  • IE專用樣式
  • CSS3實例
  • BACK

實現完美的 footer 底部排版

在 css 佈局,若內容較少時,下方總會有一片空白區,
這是很多人在 css 佈局遇到而無法解決的問題,
國外設計師寫了一個完美的 CSS Sticky Footer Layout ,
不論內容多寡都能讓底部貼緊視窗下方,
前提是一定要讓 footer 的 <div> 區塊在wrap 的<div> 標籤之外,
必須注意, #main 的 padding 值、footer 的高度和負 margin 值,必須相同。
從第 8 行開始,主要是為了讓兩欄以上浮動佈局在各瀏覽器都能相容,使用主要是為了 Goolge Chrome, 可依照你的佈局決定是否有使用的必要。

範例本站,請找一頁較少的內容縮放視窗或按全螢幕測試
Works in These Browsers :
FireFox, Google Chrome, Internet Explorer 6, 7 and 8, Mac Safari, Opera, Konqueror
<style type="text/css">
<!--
html, body, #wrap {height: 100%;}
body > #wrap {height: auto; min-height: 100%;}
#main {padding-bottom: 150px;background: #efefef;}
#footer {position: relative;margin-top: -150px;height: 150px;clear:both;}

.clearfix:after {content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;}
.clearfix {display: inline-block;}
/* Hides from IE-mac \*/
* html .clearfix { height: 1%;}
.clearfix {display: block;}
/* End hide from IE-mac */
-->
</style>
<div id="wrap">
<div id="main" class="clearfix">
<div id="content">
#content
</div>
<div id="side">
#side
</div>
</div><!-- end #main //-->
</div><!-- end #wrap //-->

<div id="footer">
</div><!-- end #footer //-->
作者網站:CSS Sticky Footer
Today : 854 Yesterday : 954 Total : 2242020
XHTML1.0 Strict | CSS 2 | Copyright © 2002-2010 by OECSPACE | 主機戰國策