IT学习者 | 文章大全 | 技术文档 | 桌面壁纸 | 网络电台 | 成语 | 歇后语 | 站长导航 | 下载 | 周公解梦 | 生日密码 | 站长助手 | Flash | IP地址查询
 您现在的位置: IT学习者 >> 文章大全 >> 网页制作 >> HTML&CSS

探索CSS实现三行三列等高布局

【 作者:greengnn    来源:网络  更新时间:2006-6-7 | 字体:

翻译自:In Search of the Holy Grail
原文:http://www.alistapart.com/articles/holygrail
这个翻译的页面版权归greengnn所有,转载请注明出处

第一步:创建一个结构

xhtml开始于header, footer, and container
<div id="header"></div>

<div id="container"></div>

<div id="footer"></div>

CSS先定义container,给将要加入的sideleft,和sideright留下个位置
#container {
 padding-left: 200px; /* LC width */
 padding-right: 150px; /* RC width */
}

我们的布局现在看起来是这样的

uploads/200602/13_074820_diagram_01.gif


图1——创建框架

第二步:增加内容元素

在第一步基础上增加内容元素
<div id="header"></div>

<div id="container">
 <div id="center" class="column"></div>
 <div id="left" class="column"></div>
 <div id="right" class="column"></div>
</div>

<div id="footer"></div>

然后分别定义widths和float 让元素排列在一条线上,还有清除footer的浮动对齐
#container .column {
 float: left;
}
#center {
 width: 100%;
}
#left {
 width: 200px; /* LC width */
}
#right {
 width: 150px; /* RC width */
}
#footer {
 clear: both;
}

这里给center元素定义了100% width,让它占满montainer的可用空间,现在的布局变成了这样

uploads/200602/13_074922_diagram_02.gif


图2:增加内容元素

第三步:把left放到正确的位置

要把left放到正确的位置,我们分两步

1.让left和center在同一水平线
#left {
 width: 200px; /* LC width */
 margin-left: -100%;
}

看看效果

uploads/200602/13_075000_diagram_03.gif


图3——left移动完成一半

2.用相对定位,把left继续移动到正确的位置
#container .columns {
 float: left;
 position: relative;
}
#left {
 width: 200px; /* LC width */
 margin-left: -100%;
 right: 200px; /* LC width */
}

让left距离他右边元素center 200px后,行了,left终于到自己位置上了

uploads/200602/13_075037_diagram_04.gif



图4——left到了自己的位置

文章共2页,当前在第1页 9 7 [1] [2] 8 :
相 关 文 章
相 关 软 件

音乐
嫁衣 画心 放生 天亮了 牡丹江 那滋味 擦肩而过 怀念过去 北京欢迎你 突然好想你 吻的太逼真 说好的幸福呢 坐上火车去拉萨 没有人比我更爱你
愚爱 心碎 稻香 带我走 醉赤壁 魔杰座 我还想她 明天过后 一定要爱你 等爱的玫瑰 原谅我一次 越单纯越幸福 最后一次的温柔 给我一首歌的时间
白狐 光荣 降临 下雨天 小酒窝 樱花草 恋爱新手 说唱脸谱 红色高跟鞋 寂寞才说爱 深深爱过你 爱上你是个错 即使知道要见面 不是因为寂寞才想你
城府 假如 花海 兰亭序 棉花糖 舍不得 最后一次 女人如烟 外滩十八号 我们的纪念 我们的无奈 心在跳情在烧 爱上你是我的错 爱情里没有谁对谁错
加入收藏留言建议自助友情链接普通友情链接站长的Blog
版权所有   COPYRIGHT 2002-2009 ★IT学习者★ ALL RIGHTS RESERVED.