zoukankan      html  css  js  c++  java
  • CSS之圣杯布局与双飞翼布局

    圣杯布局

    三行等高

    HTML:

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title></title>
        <link rel="stylesheet" href="docm.css">
    </head>
    <body>
        <div id="page">
          <div id="hd"></div>
             <div id="bd">
             <div class="main">1231111<p>我我我</p><p>我我我</p><p>我我我</p><p>我我我</p></div>
                  <div class="sub">11222</div>
                  <div class="extra">456</div>
             </div>
          <div id="ft"></div>
      </div>
    </body>
    </html>

    css:(在.bd中设置内边距,然后在.sub和.extra中设置负边距把中间的内容显示出来)

    *{
      margin: 0;
      padding: 0;
     }
     #hd{
      100%;
      height: 100px;
      background-color: #FC3D83;
     }
    .main {
               float: left;
               100%;    //中间内容自适应
               background-color: #ccc;
               padding-bottom: 9999px;       //把内容撑出去后又收回来形成等高
               margin-bottom: -9999px;     //把内容撑出去后又收回来形成等高
     }
     .sub {
               float: left;
               190px;
               margin-left: -100%;      //将内容设置到左边
               background-color: #ED1E25;
               padding-bottom: 9999px;
               margin-bottom: -9999px;
               position: relative;     //设置相对位置来配放,而双飞翼不设置
               left: -190px;      //在.bd中设置内边距,然后在.sub和.extra中设置负边距把中间的内容显示出来
                }
     .extra {
                 float: left;
                 190px;
                 margin-left: -190px;    //将内容设置到右边
                 background-color: #f0f;
                 padding-bottom: 9999px;
                 margin-bottom: -9999px;
                 position: relative;    //设置相对位置来配放,而双飞翼不设置
                 right: -190px;      //在.bd中设置内边距,然后在.sub和.extra中设置负边距把中间的内容显示出来
     }
     #bd {
              padding: 0 190px 0 190px;    //在.bd中设置内边距,然后在.sub和.extra中设置负边距把中间的内容显示出来
              background-color: #ff0;
              overflow: hidden;     //超出内容隐藏,等高的设置
     }
     #ft{
      100%;
      height: 100px;
      background-color: #5880F4;
     }

    效果如图:

    ---------------------------------------------分割线看什么看-------------------------------------------------------------

    双飞翼布局

     上面的圣杯布局其实已经挺好的,但是因为用了相对定位,所以对于布局就不太稳定,那么如何不用相对定位来实现这个效果呢,于是就有了双飞翼布局,在mian主要内容中加一个盒子包裹,再用margin-left使内容显示出来。

    三行等高

    HTML:

    <div id="page">
          <div id="hd"></div>
             <div id="bd">
                  <div class="main"><div class="inside">1231111</div></div>
                  <div class="sub">234<p>我我我<p/><p>我我我<p/><p>我我我<p/><p>我我我<p/></div>
                  <div class="extra">456</div>
             </div>
          <div id="ft"></div>
      </div>

    CSS:

    *{
      margin: 0;
      padding: 0;
     }

     #hd{
      100%;
      height: 100px;
      background-color: #FC3D83;
     }
    .main {
               float: left;
               100%;        //自适应
               background-color: #ccc;
               padding-bottom: 9999px;       //把内容撑出去后又收回来形成等高
               margin-bottom: -9999px;     //把内容撑出去后又收回来形成等高
     }
     .sub {
               float: left;
               190px;
               margin-left: -100%;
               background-color: #ED1E25;
               padding-bottom: 9999px;
               margin-bottom: -9999px;
                }
     .extra {
                 float: left;
                 190px;
                 margin-left: -190px;
                 background-color: #f0f;
                 padding-bottom: 9999px;
                 margin-bottom: -9999px;
     }
     #bd {
              background-color: #ff0;
              overflow: hidden;       //超出的内容隐藏
     }
     .inside{
      margin: 0 190px;      //中间最里的盒子设置外边距把内容显示出来
     }

     #ft{
      100%;
      height: 200px;
      background-color: #5880F4;
     }

    效果如图:

  • 相关阅读:
    把联系人从一张卡转移到另一张卡或者从一个手机转移到另一个手机
    Echarts画折线图
    Echarts画条形图
    Echarts画饼状图
    《计算机网络》读后感
    Vue.js项目无法启动:sh: 1: vue-cli-service: not found
    《Redis入门指南(第 2 版)》读后感
    翻译:《实用的Python编程》InstructorNotes
    翻译:《实用的Python编程》TheEnd
    翻译:《实用的Python编程》09_03_Distribution
  • 原文地址:https://www.cnblogs.com/xianhaiyuan/p/5183955.html
Copyright © 2011-2022 走看看