display:flex 均等排列 一行排两列或者多列,最后的元素靠左对齐

display:flex

flex-direction属性决定主轴的方向(即项目的排列方向)。

flex-direction: row | row-reverse | column | column-reverse;

  • row(默认值):主轴为水平方向,起点在左端。
  • row-reverse:主轴为水平方向,起点在右端。
  • column:主轴为垂直方向,起点在上沿。
  • column-reverse:主轴为垂直方向,起点在下沿

 

flex-wrap属性定义,如果一条轴线排不下,如何换行。

flex-wrap: nowrap | wrap | wrap-reverse;

nowrap(默认):不换行。

wrap:换行,第一行在上方。

wrap-reverse:换行,第一行在下方。

flex-flow属性是flex-direction属性和flex-wrap属性的简写形式,默认值为row nowrap。

flex-flow: || ;

 

justify-content: flex-start | flex-end | center | space-between | space-around;

  • flex-start(默认值):左对齐
  • flex-end:右对齐
  • center: 居中
  • space-between:两端对齐,项目之间的间隔都相等。
  • space-around:每个项目两侧的间隔相等。所以,项目之间的间隔比项目与边框的间隔大一倍。

 

 

align-items属性定义项目在交叉轴上如何对齐。

align-items: flex-start | flex-end | center | baseline | stretch;

  • flex-start:交叉轴的起点对齐。
  • flex-end:交叉轴的终点对齐。
  • center:交叉轴的中点对齐。
  • baseline: 项目的第一行文字的基线对齐。
  • stretch(默认值):如果项目未设置高度或设为auto,将占满整个容器的高度。

 

align-content属性定义了多根轴线的对齐方式。如果项目只有一根轴线,该属性不起作用。

align-content: flex-start | flex-end | center | space-between | space-around | stretch

  • flex-start:与交叉轴的起点对齐。
  • flex-end:与交叉轴的终点对齐。
  • center:与交叉轴的中点对齐。
  • space-between:与交叉轴两端对齐,轴线之间的间隔平均分布。
  • space-around:每根轴线两侧的间隔都相等。所以,轴线之间的间隔比轴线与边框的间隔大一倍。
  • stretch(默认值):轴线占满整个交叉轴。

 

 

以下6个属性设置在项目上。

  • order order属性定义项目的排列顺序。数值越小,排列越靠前,默认为0。 order: ;
  • flex-grow flex-grow属性定义项目的放大比例,默认为0,即如果存在剩余空间,也不放大。 flex-grow: ; /* default 0 */

如果所有项目的flex-grow属性都为1,则它们将等分剩余空间(如果有的话)。如果一个项目的flex-grow属性为2,其他项目都为1,则前者占据的剩余空间将比其他项多一倍。

  • flex-shrink flex-shrink属性定义了项目的缩小比例,默认为1,即如果空间不足,该项目将缩小。

如果所有项目的flex-shrink属性都为1,当空间不足时,都将等比例缩小。如果一个项目的flex-shrink属性为0,其他项目都为1,则空间不足时,前者不缩小。

负值对该属性无效。

  • flex-basis flex-basis属性定义了在分配多余空间之前,项目占据的主轴空间(main size)。浏览器根据这个属性,计算主轴是否有多余空间。它的默认值为auto,即项目的本来大小。
  • flex flex属性是flex-grow, flex-shrink 和 flex-basis的简写,默认值为0 1 auto。后两个属性可选。

该属性有两个快捷值:auto (1 1 auto) 和 none (0 0 auto)。

建议优先使用这个属性,而不是单独写三个分离的属性,因为浏览器会推算相关值。

  • align-self

align-self: auto | flex-start | flex-end | center | baseline | stretch;

align-self属性允许单个项目有与其他项目不一样的对齐方式,可覆盖align-items属性。默认值为auto,表示继承父元素的align-items属性,如果没有父元素,则等同于stretch。

 

ps:

flex 最后一行左对齐

.box:after { content: ""; flex: auto; }

display:flex 均等排列 一行排两列或者多列,最后的元素靠左对齐_第1张图片

上面的布局的代码为

.outbox{width:100%;height: 100%;display:flex;flex-direction:column;}
    .top{height: 80px;background: red;}
    .bottom{height: 50px;background: green;}
    .main{flex:1;}
    .main_con{height: 100%;background:#fff; display:flex}
    .left{ width:200px; float:left; height:100%; background:#369;}
    .right{ float:left;height:100%;flex:1;}


    

    

        

            
111

            
222

        

    

    

    

 

 

在浏览器中横行排列   

4
       

           
2

           
3

           
4

           
5

           
6

           
7

           
8

       

   

.page-contain{display: flex; align-items: center; flex-grow: 1;height: 100%;}
.contain{display: flex;flex-direction: row; height: 32rem; box-shadow: 10px 50px 100px rgba(0, 0, 0, .3);}
.banner1{ background:red; width: 37.5rem}
.banner2{ background:gray; width: 27.5rem ; order: 2;}
.banner3{ background:blue; width: 42.5rem}
.banner4{ background:black; width: 27.5rem}
.banner5{ background:#ff1122;width: 30.5rem}
.banner6{ background:#ccc000;width: 43.5rem}
.banner7{ background:#00ffaa;width: 32.5rem}
.panel{ height: 32rem; line-height: 32rem; font-size: 10rem; text-align: center; color: beige}

 

骰子的排列

display:flex 均等排列 一行排两列或者多列,最后的元素靠左对齐_第2张图片


       

           

               
           

       

       

           

               
               
           

       

       

           

               
               
               
           

       

       

           

               
               
           

           

               
               
           

       

       

           

               
               
           

           

                 
           

           

               
               
           

       

       


           

               
               
           

           

               
               
           

           

               
               
           

       

       


           

               
               
               
           

           

               
               
           

           

               
               
           

       

       


            
           

               
               
           

           

               
               
           

           

               
               
           

           

               
               
           

       

       


           

               
               
               
           

           

               
               
               
           

           

               
               
               
           

       

   

.saizi{display: flex;height: 100%;}
        .page{ background: black; justify-content: space-around;}
        .public{ width: 100px; height: 100px;  background: #ddd; border-radius: 10px;  box-sizing: border-box;
            box-shadow: 2px 2px 2px rgba(0, 0, 0, .2); border: 5px solid #fff; align-items: center;}
        .saizi span{ width: 20px; height: 20px; border-radius: 20px; display: inline-block;background: black;}
        .one{justify-content: center; align-items: center; }
        .two{ justify-content: space-between;}
         .two .specia_one{align-self:flex-end;}

         .three{ justify-content: space-between;}
         .three .specia_one{align-self:center;}
         .three .specia_two{align-self:flex-end;}

         .four{ justify-content: space-between;}
         .four .specia_one,.four .specia_two{align-self: flex-end;}

        .spe{ justify-content: space-between;}
         .four{ flex-direction: column;justify-content:space-between;}
    

         .five{ flex-direction: column;justify-content:space-between;}
         

         .six{flex-direction: column;justify-content:space-between;}
            
         .spe_sevec{flex-direction: column; justify-content: space-between;}
         .seven{justify-content:space-around; height: 40px; width: 100%;}
         .seven .one{align-self: center;}
         .seven .two{align-self: flex-end}
         .seven_spea{ justify-content: space-around; height: 20px;width: 100%;}

        .eight_spea{flex-direction: column;}
         .eight{justify-content: space-around; width: 100%;}

         .night_spea{flex-direction: column;}
         .night{justify-content: space-around;  width: 100%;}

 

flex布局  一行排两列或者三列

.list_cai{ display: flex;  justify-content: space-around;  flex-direction: row;  flex-wrap: wrap;}   父节点

.list_cai .list_cai_li{ width: 45%; height:100px; border: 1px solid orange; border-radius: 20rpx;}  子节点

 

flex布局最后的一个或者两个元素  靠左对齐

.list_cai:after {content: "";flex: auto; }

 

你可能感兴趣的:(HTML5,Css3)