我还是要说的布局

两栏布局

左边固定右边自适应
  • 使用float布局
/*HTML*/
<div class="left">我是左边</div>
<div class="right">我是右边</div>

/*CSS*/
 .left{
            float: left;
            width: 200px;
            background-color: #0074D9;
        }
 .right{
            margin-left: 200px;
            background-color: #954121;
        }
  • 使用position布局
/*HTML*/
<div class="left">我是左边</div>
<div class="right">我是右边</div>
/*CSS*/
.left{
            position: absolute;
            left: 0;
            width: 200px;
            background-color: #0074D9;
        }
        .right{
            margin-left: 200px;
            background-color: #954121;
        }


三栏布局

左右两边固定中间自适应
  • 使用flex布局
/*HTML*/
<div class="wrap">
    <div class="left">我是左边</div>
    <div class="middle">我是中间</div>
    <div class="right">我是右边</div>
</div>
/*CSS*/
       .wrap{
            display: flex;
        }
        .middle{
            width: 100%;
            background-color: #7f7f7f;
        }
        .left{
            width: 200px;
            background-color: #0074D9;
        }

        .right{
            width: 200px;
            background-color: #954121;
        }
  • 使用position/float+margin进行布局
 /*HTML*/
        <div class="left">我是左边</div>
       <div class="middle">我是中间</div>
       <div class="right">我是右边</div>
/*CSS*/
        .middle{
            margin: 0 200px;
            background-color: #7f7f7f

        }
        .left{
            width: 200px;
            background-color: #0074D9;
           float: left;
          /*
          position:absolute;
          left:0;
          */
        }

        .right{
            width: 200px;
            background-color: #954121;
           float: right;
           /*
          position:absolute;
         right:0;
          */
        }
  • 圣杯布局(position+float+margin负值)
/*HTML*/
<div class="wrap">
       <div class="middle">我是中间</div>
       <div class="left">我是左边</div>
       <div class="right">我是右边</div>
   </div>
/*CSS*/
       .wrap > div{
            float: left;
        }
       .wrap{
           padding: 0 200px;
       }
        .middle {
            width: 100%;
            background-color: #7f7f7f

        }

        .left {
            width: 200px;
            background-color: #0074D9;
           margin-left: -100%;
            position: relative;
            left: -200px;
        }

        .right {
            width: 200px;
            background-color: #954121;
            margin-left: -200px;
            position: relative;
           right: -200px;
        }
  • 双飞翼布局(margin+float)
/*HTML*/
 <div class="wrap">
        <div class="middle">我是中间</div>
    </div>
    <div class="left">我是左边</div>
    <div class="right">我是右边</div>
/*CSS*/
        .wrap {
            width: 100%;
            float: left;
        }

        .middle {
            background-color: #7f7f7f;
            margin: 0 200px;

        }

        .left {
            float: left;
            width: 200px;
            background-color: #0074D9;
            margin-left: -100%;
        }

        .right {
            float: left;
            width: 200px;
            background-color: #954121;
            margin-left: -200px;
        }
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 问答题47 /72 常见浏览器兼容性问题与解决方案? 参考答案 (1)浏览器兼容问题一:不同浏览器的标签默认的外补...
    _Yfling阅读 13,792评论 1 92
  • 前言 温馨提示:本文较长,图片较多,本来是想写一篇 CSS 布局方式的,但是奈何 CSS 布局方式种类太多并且实现...
    sunshine小小倩阅读 3,164评论 0 59
  • 收听音频,戳链接,旧号itclan已暂停使用,欢迎关注微信itclanCoder公众号可收听更多音频 前言 关于网...
    itclanCoder阅读 8,204评论 3 30
  • Block的使用场景: 1、作为本地变量 语法: 实现过程: 2、作为属性(可以反向传值时使用) 语法 实现过程 ...
    Ching_Han阅读 370评论 0 4
  • 追剧人, 追的确是心情, 任夜间这厚重的时钟敲过…… 追剧人, 仿若追空了一个时代! 没有感动, 没有眼泪, 仅剩...
    若水倾城阅读 642评论 0 0