zoukankan      html  css  js  c++  java
  • 左侧固定,右侧自适应的布局方式(新增评论区大佬教的方法)

    一.浮动布局

    1.先让固定宽度的div浮动!使其脱离文档流。
    2.margin-left的值等于固定div的宽度相等。

       .aside{
            float: left;
             200px;
            background-color: red;
        }
        .content{
            margin-left: 200px;
            background-color: blue;
        }
        
    <div class="aside">
        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Labore provident dolor in voluptatum tempore non, placeat obcaecati totam ut delectus libero excepturi distinctio asperiores odit nobis soluta, esse aspernatur beatae.
    </div>
    <div class="content">
        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Labore provident dolor in voluptatum tempore non, placeat obcaecati totam ut delectus libero excepturi distinctio asperiores odit nobis soluta, esse aspernatur beatae.
    </div>
    
    

    二.margin的负值(3个div)

    1. 是固定宽度的div脱离文档流。
    2. 利用marin负值可以使得,后面的div可以与前面的div 保持同行显示。
    3. 给包裹内容的div加margin-left 可以使得与左边的文字不重叠

      .aside{
          float: left;
          margin-right: -200px;
           200px;
          background-color: red;
      }
      .content{
          float: right;
      }
      .content .inner{
          margin-left: 200px;
          background-color: blue;
      }
      
       <div class="aside">
         Lorem ipsum dolor sit amet, consectetur adipisicing elit. Labore provident dolor in voluptatum tempore non, placeat obcaecati totam ut delectus libero excepturi distinctio asperiores odit nobis soluta, esse aspernatur beatae.
      </div>
      <div class="content">
         <div class="inner">
            Lorem ipsum dolor sit amet, consectetur adipisicing elit. Labore provident dolor in voluptatum tempore non, placeat obcaecati totam ut delectus libero excepturi distinctio asperiores odit nobis soluta, esse aspernatur beatae.
         </div> 
      

      </div>

    三.calc()计算属性

    注意:使用calc计算属性的时候 运算符(- +等等)两边必须有空格

    1. 注意两个div必须一左一右浮动。
    2. calc的宽度必须要减去的宽度要与固定宽度保持一致。

        .aside{
            float: left;
             200px;
            background-color: red;
        }
        .content{
            calc:(100% - 200px);
            background-color: blue;
        }
      

      <div class="aside">

        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Labore provident dolor in voluptatum tempore non, placeat obcaecati totam ut delectus libero excepturi distinctio asperiores odit nobis soluta, esse aspernatur beatae.
         &lt;/div&gt;
       &lt;div class="content"&gt;
           Lorem ipsum dolor sit amet, consectetur adipisicing elit. Labore provident dolor in voluptatum tempore non, placeat obcaecati totam ut delectus libero excepturi distinctio asperiores odit nobis soluta, esse aspernatur beatae.        
        &lt;/div&gt;
      
      

    四.flex布局

    1. 需要给父级div设置display: flex属性。
    2. 固定宽度的div设置flex: 0 0 200px即可。
    3. 内容区域的div直接写出flex: 1即可。

      .container{
          display: flex;
      }
      .aside{
          flex: 0 0 200px;
          background-color: red; 
      }
      .content{
          flex: 1;
          background-color: blue;
      }
      &lt;div class="container"&gt;
          &lt;div class="aside"&gt;
          Lorem ipsum dolor sit amet, consectetur adipisicing elit. Labore provident dolor in voluptatum tempore non, placeat obcaecati totam ut delectus libero excepturi distinctio asperiores odit nobis soluta, esse aspernatur beatae.
          &lt;/div&gt;
          &lt;div class="content"&gt;
          Lorem ipsum dolor sit amet, consectetur adipisicing elit. Labore provident dolor in voluptatum tempore non, placeat obcaecati totam ut delectus libero excepturi distinctio asperiores odit nobis soluta, esse aspernatur beatae.
          &lt;/div&gt;
      &lt;/div&gt;
      
      

    五.左侧浮动,右侧overflow:hidden

    .aside{
         200px;
        float: left;
        background-color: red;
    }
    .content{
        overflow: hidden;
        background-color: blue;
    }
    &lt;div class="aside"&gt;
            Lorem ipsum dolor sit amet, consectetur adipisicing elit. Labore provident dolor in voluptatum tempore non, placeat obcaecati totam ut delectus libero excepturi distinctio asperiores odit nobis soluta, esse aspernatur beatae.
        &lt;/div&gt;
        &lt;div class="content"&gt;
            Lorem ipsum dolor sit amet, consectetur adipisicing elit. Labore provident dolor in voluptatum tempore non, placeat obcaecati totam ut delectus libero excepturi distinctio asperiores odit nobis soluta, esse aspernatur beatae.
        &lt;/div&gt;
    

    阮一峰老师写的教程权威传送门:http://www.ruanyifeng.com/blo...

    原文地址:https://segmentfault.com/a/1190000016694777
  • 相关阅读:
    bzoj4554: [Tjoi2016&Heoi2016]游戏
    bzoj3166: [Heoi2013]Alo
    luogu3398 仓鼠找sugar
    bzoj3261: 最大异或和
    bzoj3446: [Usaco2014 Feb]Cow Decathlon
    BZOJ1742[Usaco2005 nov]Grazing on the Run 边跑边吃草
    bzoj2750: [HAOI2012]Road
    bzoj4448: [Scoi2015]情报传递
    bzoj2809: [Apio2012]dispatching
    bzoj 1452
  • 原文地址:https://www.cnblogs.com/lalalagq/p/9809085.html
Copyright © 2011-2022 走看看