教程集 www.jiaochengji.com
教程集 >  CSS教程  >  正文 CSS DIV自适应高度布局

CSS DIV自适应高度布局

发布时间:2019-10-26   编辑:jiaochengji.com
教程集为您提供CSS DIV自适应高度布局等资源,欢迎您收藏本站,我们将为您提供最新的CSS DIV自适应高度布局资源

要实现的是head foot固定,中间区域随内容高度自适应,拖动滚动条时foot永远居底。
SolarDreamStudios的方案给了我一个很好的思路,但关键部分是原创的,一直以为会比SolarDreamStudios的方案好,结果仔细看他们的代码,才发现其实原理都差不多,不过他们似乎在兼容性上下了更多工夫,具体未测试。
A. 宽度100%自适应
结构代码

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy7314')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy7314><body>
<div id="head">head</div>
<div id="head_height"></div>
<div id="middle"></div>
<div id="foot_height"></div>
<div id="foot">foot</div>
</body>

表现代码

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy2551')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy2551>#head { width:100%; text-align:center; background:#FF9400; height:100px; position:absolute; top:0;}
    #head_height { height:100px;}
#middle { margin:20px;}
#foot { width:100%; text-align:center; background:#f00; height:100px; position:absolute; bottom:0;}
* html #foot { bottom:-1px;}
    #foot_height { height:100px;}

B. 宽度固定居中
结构代码

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy4912')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy4912><body>
<div id="head">
    <div id="head_content">head</div>
</div>
<div id="head_height"></div>
<div id="middle"></div>
<div id="foot_height"></div>
<div id="foot">
    <div id="foot_content">foot</div>
</div>
</body>

表现代码

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy9262')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy9262>#head { width:100%; text-align:center; position:absolute; top:0; left:0;}
    #head_content { line-height:100px; width:700px; margin:0 auto; background:#FF9400; height:100px;}
    #head_height { height:100px;}
#middle { margin:20px;}
#foot { width:100%; text-align:center; position:absolute; bottom:0;}
* html #foot { bottom:-1px;}
    #foot_content { line-height:100px; width:700px; margin:0 auto; background:#f00; height:100px;}
    #foot_height { height:100px;}

测试环境IE6.0和FF1.5,IE环境下因为BUG有时会自动出现滚动条(SolarDreamStudios的方案一样),FF下为完美效果。

您可能感兴趣的文章:
css div设定最小高度又自适应高度
高度100%的绝对定位自适应布局
css DIV三列高度自适应
流动布局插件 jFL
css 高度自适应代码与自适应高度css兼容ie,firefox
CSS基本布局16例
jQuery实现等比例缩放大图片让大图片自适应页面布局
div 自适应高度
页脚最小高度100%保持在页面底部的布局方法
DIV CSS网页布局对SEO优化有哪些影响

[关闭]
~ ~