div自适应宽度:三列自由式布局 770-1024自适应宽度!



  这个例子是最典型实用上中下并且中间分 3列css布局有以下2个特点:
  1.中间 3列效果可以任意实现单列背景色
  2.整体最窄770px最宽1024px也就是说窗口小于770xp就出底部滚动条如果大于1024px自动屏幕居中
  最外层wrapper把所有内容都嵌套在里边整体相对定位maxmin已经很好控制了最窄最宽值但对IE没有作用如果没有其他布局穿插层其实写在body内就可以层嵌套

\" style=\"margin:0px 2px -3px 0px\" alt=\"div css xhtml xml Example Source Code\"/> Example Source Code [www.52css.com]
#wrapper{width:auto;border:1pxsolid#000;min-width:770px;max-width:1024px;text-align:left;margin-left:auto;margin-right:auto;position:relative;}


wrapper下级outerheaderfooter
其中header绝对定位footer相对定位;outer分别对左右有130px外边距这是兼容非IE关键

\" style=\"margin:0px 2px -3px 0px\" alt=\"div css xhtml xml Example Source Code\"/> Example Source Code [www.52css.com]
#outer{margin-left:130px;margin-right:130px;background:silver;border-left:1pxsolid#000;border-right:1pxsolid#000;color:#000;}
#header{position:absolute;top:0;left:0;width:100%;height:70px;line-height:70px;border-bottom:1pxsolid#000;overflow:hidden;background:#0ff;text-align:center;font-size:xx-large}
#footer{width:100%;clear:both;line-height:50px;border-top:1pxsolid#000;background:#ffc;color:#000;text-align:center;position:relative;}


  outer下级clearheaderouterwraprightclearer
  clearheader用做填补header空白clearer是个常用填充hack使用方法
  outerwrap宽为什么是99%而不是100%?上层outer有边框100%宽再加2个边框象素就会撑大FF有明显效果
  right处理很经典IE下解析为定位FF下则为浮动负边距处理也刚好使用上outer留出空白

\" style=\"margin:0px 2px -3px 0px\" alt=\"div css xhtml xml Example Source Code\"/> Example Source Code [www.52css.com]
#clearheader{height:72px;}
.outerwrap{float:left;width:99%;}
#right{
position:relative;
width:130px;float:right;left:1px;
margin-right:-129px;
}
*html#right{margin-right:-130px;margin-left:-3px}
.clearer{height:1px;overflow:hidden;margin-top:-1px;clear:both;}


  outerwrap内centrecontentleftclearer就很简单了思路类似上边介绍说明
  <!--[gteIE5]>指定IE5.0及版本以上浏览器有效
  使用expression思路方法实现对IE5.0及以上版本宽度条件控制

\" style=\"margin:0px 2px -3px 0px\" alt=\"div css xhtml xml Example Source Code\"/> Example Source Code [www.52css.com]
body{width:expression(documentElement.clientWidth<770?(documentElement.clientWidth0?(body.clientWidth<770?\"770\":\"auto\"):\"770px\"):\"auto\");}
#wrapper{width:expression(documentElement.clientWidth>1024?(documentElement.clientWidth0?(body.clientWidth>1024?\"1024\":\"auto\"):\"1024px\"):\"auto\");}


IE6.0和FF1.5测试通过查看运行效果:

\" style=\"margin:0px 2px -3px 0px\" alt=\"div css xhtml xml Source Code to Run\"> Source Code to Run [www.52css.com]

=\"ubbbuttonrt\">[ 可先修改部分代码 再运行查看效果 ]


  开始只想搞清楚老外是如何实现居中minmax没想到最后是expression太失望了其实这里使用脚本控制更好另外老外原文Minwidthof800px是错CSS定义就是770px后来截屏确认也是770px
  总来说这是个很复杂布局例子融合了很多经典使用方法和定义同时很传统和实用类似复杂布局 4层嵌套实现对于传统布局来说还是比较有优势
  
Tags:  css自适应宽度 自适应宽度 iframe自适应宽度 div自适应宽度

延伸阅读

最新评论

发表评论