热门搜索 :
考研考公
您的当前位置:首页正文

双飞翼布局与圣杯布局的实现要点

来源:东饰资讯网
双飞翼布局
HTML

header,content,footer三个div,content中设置center,left,right三个div,center层放在left和right的前面。

CSS:

1.body设置最小宽度,min-width:xxxpx;将中间层宽度设为:width:100%;
2.将中间层、左右层都设置左浮动。

让左右元素浮上去

3.left设置左边距为margin-left:-100%;对于浮动元素,负margin值等于100%可以让元素上去,并且和content的位置头部对齐。
4.right设置margin-left:负的right宽度;

解除遮盖的问题

5.center中间再设置一个div,class设置为center-wrap,定义它的最小宽度为min-height:200px;设置左边距margin-left:left的宽度,margin-right:right的宽度;
6.footer部分清除浮动。

圣杯布局
HTML结构与双飞翼相同

CSS:
1.body设置最小宽度,min-width:(2倍left+right的宽度)px;将中间层宽度设为:width:100%;

让左右元素浮上去

2.left、right、center设置定位和浮动position:relative;float:left;
3.给left边栏设置right:left的宽度,让其移动位置。设置负边距100%(#center的宽度)margin:-100%,让其跑到上面。
4.right设置负边距margin-right:-right的宽度让其跑到上面。

解除遮盖的问题

5.container设置左右padding为left和right的宽度,用于预留左右边栏的空间。
6.footer部分清除浮动。

Top