zoukankan      html  css  js  c++  java
  • 圣杯布局和双飞翼布局的理解和区别,并用代码实现

      作用:圣杯布局和双飞翼布局解决的问题是一样的,就是两边顶宽,中间自适应的三栏布局,中间栏要在放在文档流前面以优先渲染。
      区别:圣杯布局,为了中间div内容不被遮挡,将中间div设置了左右padding-left和padding-right后,将左右两个div用相对布局position: relative并分别配合right和left属性,以便左右两栏div移动后不遮挡中间div。双飞翼布局,为了中间div内容不被遮挡,直接在中间div内部创建子div用于放置内容,在该子div里用margin-left和margin-right为左右两栏div留出位置。

    圣杯布局:

    <body>
    <div id="hd">header</div>
    <div id="bd">
      <div id="middle">middle</div>
      <div id="left">left</div>
      <div id="right">right</div>
    </div>
    <div id="footer">footer</div>
    </body>
    
    <style>
    #hd{
        height:50px;
        background: #666;
        text-align: center;
    }
    #bd{
        /*左右栏通过添加负的margin放到正确的位置了,此段代码是为了摆正中间栏的位置*/
        padding:0 200px 0 180px;
        height:100px;
    }
    #middle{
        float:left;
        100%;/*左栏上去到第一行*/
        height:100px;
        background:blue;
    }
    #left{
        float:left;
        180px;
        height:100px;
        margin-left:-100%;
        background:#0c9;
        /*中间栏的位置摆正之后,左栏的位置也相应右移,通过相对定位的left恢复到正确位置*/
        position:relative;
        left:-180px;
    }
    #right{
        float:left;
        200px;
        height:100px;
        margin-left:-200px;
        background:#0c9;
        /*中间栏的位置摆正之后,右栏的位置也相应左移,通过相对定位的right恢复到正确位置*/
        position:relative;
        right:-200px;
    }
    #footer{
        height:50px;
        background: #666;
        text-align: center;
    }
    </style>
    

    双飞翼布局:

    <body>
    <div id="hd">header</div> 
      <div id="middle">
        <div id="inside">middle</div>
      </div>
      <div id="left">left</div>
      <div id="right">right</div>
      <div id="footer">footer</div>
    </body>
    
    <style>
    #hd{
        height:50px;
        background: #666;
        text-align: center;
    }
    #middle{
        float:left;
        100%;/*左栏上去到第一行*/     
        height:100px;
        background:blue;
    }
    #left{
        float:left;
        180px;
        height:100px;
        margin-left:-100%;
        background:#0c9;
    }
    #right{
        float:left;
        200px;
        height:100px;
        margin-left:-200px;
        background:#0c9;
    }
    
    /*给内部div添加margin,把内容放到中间栏,其实整个背景还是100%*/ 
    #inside{
        margin:0 200px 0 180px;
        height:100px;
    }
    #footer{  
       clear:both; /*记得清楚浮动*/  
       height:50px;     
       background: #666;    
       text-align: center; 
    } 
    </style>
    

      

  • 相关阅读:
    机器学习常用算法
    判别式模型与生成式模型
    数据清洗方法
    机器学习项目流程清单
    免费的论文查重网站
    (转载)python应用svm算法过程
    opencv图像阈值设置的三种方法
    Tensorflow读取csv文件(转)
    tensorflow的数据输入
    为什么有些图像在显示前要除以255?(zhuan)
  • 原文地址:https://www.cnblogs.com/zjxiang008/p/15791481.html
Copyright © 2011-2022 走看看