星空网 > 软件开发 > 网页设计

圣杯布局的实现过程

圣杯布局和双飞翼布局,他们的都要求三列布局,中间宽度自适应,两边定宽,这样做的优势是重要的东西放在文档流前面可以优先渲染,而双飞翼布局是对圣杯布局的一种改良,下一篇文章会讲到。

圣杯布局:用到浮动、负边距、相对定位,不添加额外标签

DOM结构:

圣杯布局的实现过程
<div >Header</div><div >  <div >Main</div>  <div >Left</div>  <div >Right  </div></div><div >Footer</div>
圣杯布局的实现过程

样式:

圣杯布局的实现过程
  <style>    body{padding:0;margin:0}    .header,.footer{width:100%; background: #666;height:30px;clear:both;}    .bd{      padding-left:150px;      padding-right:190px;    }    .left{      background: #E79F6D;      width:150px;      float:left;      margin-left:-100%;      position: relative;      left:-150px;    }    .main{      background: #D6D6D6;      width:100%;      float:left;    }    .right{      background: #77BBDD;      width:190px;      float:left;      margin-left:-190px;      position:relative;      right:-190px;    }  </style>
圣杯布局的实现过程

 

左中右部分样式变化过程

1、中间部分需要根据浏览器宽度的变化而变化,所以要用100%,这里设左中右向左浮动,因为中间100%,左层和右层根本没有位置上去

圣杯布局的实现过程
    .left{      background: #E79F6D;      width:150px;      float:left;    }    .main{      background: #D6D6D6;      width:100%;      float:left;    }    .right{      background: #77BBDD;      width:190px;      float:left;    }
圣杯布局的实现过程

圣杯布局的实现过程

2、把左层负margin150后,发现left上去了,因为负到出窗口没位置了,只能往上挪

 .left{      background: #E79F6D;      width:150px;      float:left;      margin-left:-150px;    }

圣杯布局的实现过程

3、那么按第二步这个方法,可以得出它只要挪动窗口宽度那么宽就能到最左边了,利用负边距,把左右栏定位

圣杯布局的实现过程
    .left{      background: #E79F6D;      width:150px;      float:left;      margin-left:-100%;    }    .right{      background: #77BBDD;      width:190px;      float:left;      margin-left:-190px;    }
圣杯布局的实现过程

圣杯布局的实现过程

 4、然而问题来了,中间被左右挡住了啊,只好给外层加padding了

    .bd{      padding-left:150px;      padding-right:190px;    }

圣杯布局的实现过程

5、但是加了之后左右栏也缩进来了,于是采用相对定位方法,各自相对于自己把自己挪出去,得到最终结果

圣杯布局的实现过程
    .left{      background: #E79F6D;      width:150px;      float:left;      margin-left:-100%;      position: relative;      left:-150px;    }    .right{      background: #77BBDD;      width:190px;      float:left;      margin-left:-190px;      position:relative;      right:-190px;    }
圣杯布局的实现过程

圣杯布局的实现过程

原文转自http://www.cnblogs.com/tinyphp/p/4742922.html




原标题:圣杯布局的实现过程

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

实用干货:截港、结关、通关?这些知识点要牢记!:https://www.ikjzd.com/articles/121472
风靡“疫”时,撞上宅经济风口,这些产品的需求增加了350%:https://www.ikjzd.com/articles/121473
速卖通如何差异化选品?:https://www.ikjzd.com/articles/121474
亚马逊近期热卖选品大揭秘,掘金跨境新蓝海:https://www.ikjzd.com/articles/121475
物流价格上涨,速卖通物流模板怎么调整?:https://www.ikjzd.com/articles/121476
亚马逊重申规则,装逼卖傻碰瓷的该醒醒了!:https://www.ikjzd.com/articles/121477
2024.03.29亚马逊选品推荐(仅供参考):宠物饮水机滤芯片:https://www.kjdsnews.com/a/1836532.html
想要搞钱,就去做离搞钱最近的事:https://www.kjdsnews.com/a/1836533.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流