Groups
Groups
Sign in
Groups
Groups
南瓜社区
Conversations
About
Send feedback
Help
用CSS让页脚始终保持底部的方法
7 views
Skip to first unread message
Pittzh
unread,
Aug 11, 2008, 9:37:27 PM
8/11/08
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to 南瓜社区
有时候,我们用CSS创建一个高度自适应布局,如何保证页脚(footer)在内容不超过一屏的情况下始终保持在布局最下方是一个比较头疼的事。我
看过一些利用绝对定位的例子,但总感觉不是那么完美,经过一下午的研究总结出一个利用负值外补丁的方法来实现这个效果的方法。下面我们看步骤:
1、为了让浏览器识别高度100%我们需要先给 html 和 body 加上一个高度值,同时清除所有元素的 margin 和
padding。顺便提一下,经过我的测试,html 和 body 的 height: 100%; 等于整个浏览器窗口的总高度,无论内容是否超过
一屏。而它们下一级子元素 height: 100%; 则等于第一屏的高度。如何,是不是有点不好理解?
* {
margin: 0;
padding: 0;
}
html, body {
height: 100%;
}
2、因为上面提到的问题,所以为了让布局自适应高度,我们要加上 min-height: 100%;,虽然IE不支持这个属性但是IE的
height: 100%; 有同样的作用:
#wrapper {
min-height: 100%;
}
* html #wrapper {
height: 100%;
}
这样,一个最简单的最小高度满一屏的自适应布局就做好了。为了便于查看,我加了一些宽度和背景色修饰,如下:
* {
margin: 0;
padding: 0;
}
html, body {
height: 100%;
text-align: center;
font: 12px/1.4 Verdana, sans-serif;
background: #f00;
}
#wrapper {
width: 770px;
min-height: 100%;
background: #ccc;
margin: auto;
text-align: left;
}
* html #wrapper {
height: 100%;
}
Reply all
Reply to author
Forward
0 new messages