当前位置: 首页 > 图文教程 > 网页制作 > CSS样式表 > 不用float实现div模块居中布局

CSS样式表
css 兼容ie6,ie7,ff的fixed,元素上下端固定定位方法
CSS解决链接锚点定位偏移的代码
一个css transform效果 很有图片的感觉
ie6,ie7,firefox的textarea滚动条、边框
12种CSS BUG解决方法与技巧
CSS 常用设置备忘
table中td内容换行问题
外部引用CSS中 link与@import的区别
CSS background-position 属性 定位图片
css 解决英文字符与阿位伯数字自动换行
div ,frame等空间的透明实现代码
CSS中几种浏览器对不同版本的支持与区分写法
多个浏览器对容器宽度实际像素的解释
CSS 用ul li做圆角表格
CSS 之dl dt dd模拟表格实例代码
创建超链接及css 样式设置
页面位置 top、postop、scrolltop、offsetTop、scrollHeight、offsetHeight、clientHe
css float 解析学习
学习DIV+CSS难不难 需要掌握哪些知识
IE8 CSS hack

CSS样式表 中的 不用float实现div模块居中布局


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 82 ::
收藏到网摘: n/a

最常见的div+css网页布局形式:上、中左、中右、底四个模块,宽度760px,整体页面居中。
结构代码,top left right foot 四个模块全部独立、互不嵌套。
<div id="top">head</div>
<div id="left">
<div id="left_module">left</div>
</div>
<div id="right">
<div id="right_module">right</div>
</div>
<div id="foot" >foot</div>
顶部属于常规定义。
#top { height:100px; background:#ccc; width:760px; margin:auto; text-align:center;}
方法A: 外层left定义为760px宽并居中;内层left_module定义为实际的左侧宽度280px,且绝对定位,top值等于顶部定义的高度。
这种方法的好处是:left right 两个模块代码片断可以互换调整显示优先级。
#left { width:760px; margin:auto;}
#left_module { width:280px; position:absolute; top:100px; padding:10px;}
方法B: 外层left定义为760px宽并居中,相对浮动于top;内层left_module定义为实际的左侧宽度280px,且绝对定位。
这种方法的好处是:顶部的高度可以自由延伸。
#left { width:760px; margin:auto; position:relative;}
#left_module { width:280px; position:absolute; padding:10px;}
外层right定义为760px宽并居中,内层right_module定义为实际的右侧宽度440px,使用margin语法居左。right_module定义的背景色是实际右侧的背景色,定义的高度就是实际中间模块的高度;right的背景色就是实际左侧的背景色。
#right { width:760px; margin:auto; background:#E8E8E8;}
#right_module { width:440px; background:#F0F0F0; height:360px; margin:0 0 0 auto; padding:10px;}
底部也属于常规定义。
#foot { height:100px; background:#ccc; width:760px; margin:auto; text-align:center;}
测试环境IE6.0和FF1.5,都是最俗的语法,非常简单,实用有限,可做技术参考。