使用CSS定位footer。请改变浏览器窗口的高度,以观察footer效果。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>使用CSS定位footer</title> <style type="text/css"> body,html { margin: 0; padding: 0; font: 12px/1.5 arial; height:100%; } #container { position: relative; min-height:100%; } #content { padding: 10px; padding-bottom: 60px; /*(20px font-size x 2 line-height) + (2 * 10px padding) = 60px*/ } #footer { position: absolute; bottom: 0; padding: 10px 0; background-color: #AAA; width: 100%; } #footer h1 { font: 20px/2 Arial; margin:0; padding:0 10px; } </style> </head> <body> <div id="container"> <div id="content"> <h1>Content</h1> <p>请改变浏览器窗口的高度,以观察footer效果。</p> <p><a href="http://www.webjx.com">万象互联网络资讯网,为您提供最好的网页教程。</a>请改变浏览器窗口的高度,以观察footer效果。万象互联网络资讯网,为您提供最好的网页教程。万象互联网络资讯网,为您提供最好的网页教程。万象互联网络资讯网,为您提供最好的网页教程。万象互联网络资讯网,为您提供最好的网页教程。万象互联网络资讯网,为您提供最好的网页教程。万象互联网络资讯网,为您提供最好的网页教程。</p> <p><a href="http://www.webjx.com">万象互联网络资讯网,为您提供最好的网页教程。</a>请改变浏览器窗口的高度,以观察footer效果。万象互联网络资讯网,为您提供最好的网页教程。万象互联网络资讯网,为您提供最好的网页教程。万象互联网络资讯网,为您提供最好的网页教程。万象互联网络资讯网,为您提供最好的网页教程。万象互联网络资讯网,为您提供最好的网页教程。万象互联网络资讯网,为您提供最好的网页教程。</p> </div> <div id="footer"> <h1>Footer</h1> </div> </div> </body> </html>
[ 提示:你可先修改部分代码,再按Ctrl+A 全部选择 ]