下面图老师小编跟大家分享最小高度100%页脚保持在底部的布局方法,一起来学习下过程究竟如何进行吧!喜欢就赶紧收藏起来哦~
【 tulaoshi.com - Web开发 】
有时候,我们用CSS创建一个高度自适应布局,如何保证页脚(footer)在内容不超过一屏的情况下始终保持在布局最下方是一个比较头疼的事。我看过一些利用绝对定位的例子,但总感觉不是那么完美,经过一下午的研究总结出一个利用负值外补丁的方法来实现这个效果的方法,兼容IE5.0+,Opera 8.5+,Firefox 1.5+。下面我们看步骤:
1、为了让浏览器识别高度100%我们需要先给 html 和 body 加上一个高度值,同时清除所有元素的 margin 和 padding。顺便提一下,经过我的测试,html 和 body 的 height: 100%; 等于整个浏览器窗口的总高度,无论内容是否超过一屏。而它们下一级子元素 height: 100%; 则等于第一屏的高度。如何,是不是有点不好理解?
* {margin: 0;padding: 0;}html, body {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%;} (本文来源于图老师网站,更多请访问http://www.tulaoshi.com/webkaifa/)
#out-content {padding-bottom: 50px;}#out-content:after {  clear: both;  display: block;  font: 1px/0px serif;  content: ".";  height: 0;  visibility: hidden;}* html #out-(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/webkaifa/)e type="text/css"/*![CDATA[*/* { margin: 0; padding: 0;}html, body { height: 100%; text-align: center; font: 12px/1.4 Verdana, sans-serif;}#wrapper { width: 100%; min-height: 100%; background: #ccc; margin: auto; text-align: left;}* html #wrapper { height: 100%;}#header { background: Green; height: 40px;}#out-content { padding-bottom: 50px;}#out-content:after {  clear: both;  display: block;  font: 1px/0px serif;  content: ".";  height: 0;  visibility: hidden;}* html #out-content { height: 1%;}#sidebar { float: left; background: Gray; margin-right: -200px; width:200px;}#content-box { float: right; width: 100%; background: Olive;}#content { margin-left: 200px;}#footer { height: 50px; background: Background; margin: -50px auto 0;}/*]]*//style/headbodydiv id="wrapper"  div id="header"h3header/h3code#header {background: Green;height: 40px;}/code /div  div id="out-content"div id="content-box"  div id="content"h3content/h3code#content {  float: right;  width: 80%;  background: Olive;} /code/div/divdiv id="sidebar"  h3sidebar/h3  code#sidebar {  float: left;  width: 20%;  background: Gray;  }/code /div  /div/divdiv id="footer"  h3footer/h3  code#footer {  height: 50px;  background: Background;  width:770px;  margin: -50px auto 0;  }/code /div/body/html 
其他问题,如果有人希望中间两栏高度相同的话可以使用图片欺骗法,见 创建各栏同高的多栏布局。
OK,经过以上方法,这个布局应该是比较完美了。上一页 1 2 3
                        来源:http://www.tulaoshi.com/n/20160219/1604475.html
看过《最小高度100%页脚保持在底部的布局方法》的人还看了以下文章 更多>>