zoukankan      html  css  js  c++  java
  • flex布局

    子元素盒子居中,flex属性加在父元素身上,而不是自身

      <h3>子元素盒子居中,flex属性加在父元素身上,而不是自身</h3>
      <div class="box1">
        <div>box1</div>
      </div>
    
      h3 {
        margin-top: 20px;
      }
    
      .box1 {
         400px;
        height: 300px;
        border: 1px solid red;
        display: flex;
        justify-content: center;
        align-items: center;
      }
    
      .box1 div {  
         200px;
        height: 200px;
        background-color: pink;
        /* 居中子盒子中所有元素 并且不会换行 */ 
        display: -webkit-box;
        -webkit-box-pack: center;
        -webkit-box-align: center;
      }

     

    按比例自适应带一个固定宽度  默认 flex-direction:row; 所以这里没写 下面的横向加了 因为默认的所以没加

       <h3>按比例自适应带一个固定宽度</h3>
        <div class="box2">
          <div>1</div>
          <div>2</div>
          <div>3</div>
         </div>
    
      .box2{display:-webkit-flex; 400px;}
      .box2 div:nth-of-type(1){100px;background-color:red;}
      .box2 div:nth-of-type(2){flex:2;background-color:pink;}
      .box2 div:nth-of-type(3){flex:3;background-color:blue;border:4px solid black;}

     

    按比例自适应完全按比例-横向  

       <h3>按比例自适应完全按比例-横向</h3>
        <div class="box3">
          <div>1</div>
          <div>2</div>
          <div>3</div>
        </div>
    
      .box3{ 400px;display:-webkit-flex;flex-direction:row;}
      .box3 div:nth-of-type(1){flex:1;background-color:red;}
      .box3 div:nth-of-type(2){flex:2;background-color:pink;}
      .box3 div:nth-of-type(3){flex:3;background-color:orange;}

    按比例自适应完全按比例-纵向 flex-direction:column; 需要说明 不是默认的 默认是横向 也就是 flex-direction:row; 

       <h3>按比例自适应完全按比例-纵向</h3>
        <div class="box4">
          <div>1</div>
          <div>2</div>
          <div>3</div>
       </div>
    
      .box4{display:-webkit-flex;flex-direction:column; 400px;}
      .box4 div:nth-of-type(1){flex:1;background-color:red;}
      .box4 div:nth-of-type(2){flex:2;background-color:pink;}
      .box4 div:nth-of-type(3){flex:3;background-color:orange;}

     自身居中并且左右散开 就像float 一样 左边 left 右边 right 

        display: flex;
        align-items: center;
        justify-content: space-between;

  • 相关阅读:
    微信发送模板消息
    主从复制 读写分离
    php nginx反向代理
    go开发工具goclipse的安装
    安装go1.11.2
    基于科大讯飞AIUI平台自定义语义库的开发
    转载--php 7.2 安装 mcrypt 扩展
    mysql取出字段数据的精度
    sublime 2 格式化json
    RESTful接口需知道
  • 原文地址:https://www.cnblogs.com/Model-Zachary/p/6435405.html
Copyright © 2011-2022 走看看