好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

flex order 顺序

flex order 排序

一般情况下浏览器会把元素从左到右或者从上到下排列,如果我们想要更改它们的排列顺序该如何做呢?使用 order 就可以轻松的 修改 。数字越大越往后,数字越小越在前。

1. 官方定义

order 属性 设置或检索弹性盒模型对象的子元素出现的順序。

2. 解释

子元素可以通过设置 order 数值的大小来设定在 页面 中出现的顺序,数值小的在前,数值大的在后。

3. 语法

   .item-child   { 
     order  :  ; 
 } 
 

属性 说明

参数 名称 参数类型 解释 order number 数值越小排位越靠前

4.兼容性

IE Edge Firefox Chrome Safari Opera ios android 10+ 12+ 28+ 4+ 6.1+ 12.1+ 7+ 4.4

5. 实例

子元素 child-1 在右侧 child-2 在左侧。

    < div   class   =  " demo "   >  
       < div   class   =  " child-1 "   >  
        1
       </ div  >  
       < div   class   =  " child-2 "   >  
        2
       </ div  >  
   </ div  >  
 

   .demo   { 
      dis play  :  flex ; 
 } 
  .child-1   { 
     flex  : auto ; 
     order  :  ; 
     background  :   #000  ; 
 } 
  .child-2   { 
     flex  : auto ; 
     order  :  ; 
     background  :   rgb  ( , ,  )  ; 
 } 

 

效果 图

  <!DOCTYPE html> 
   < html   lang   =  " en "   >  
   < head  >  
       <  Meta    charset   =  " UTF-8 "   >  
       <  Meta    name   =  " viewport "    content   =  " width=device-width, initial-scale=1.0 "   >  
       <  Meta    http-equiv   =  " X-UA-Compatible "    content   =  " ie=edge "   >  
       < title  >  Document   </ title  >  
       < style  >   
         .demo   { 
      dis play  :  flex ; 
 } 
  .child-1   { 
     flex  : auto ; 
     order  :  ; 
     background  :   #000  ; 
 } 
  .child-2   { 
     flex  : auto ; 
     order  :  ; 
     background  :   rgb  ( , ,  )  ; 
 } 
        </ style  >  
   </ head  >  
   < body  >  
   < div   class   =  " demo "   >  
       < div   class   =  " child-1 "   >  
        1
       </ div  >  
       < div   class   =  " child-2 "   >  
        2
       </ div  >  
   </ div  >  
   
   </ body  >  
   </ html  >  
 

子元素 child-1 在右侧 child-2 在左侧 效果 图

子元素 child-1 在下 child-2 在上。

    < div   class   =  " demo "   >  
       < div   class   =  " child-1 "   >  
        1
       </ div  >  
       < div   class   =  " child-2 "   >  
        2
       </ div  >  
   </ div  >  
 

   .demo   { 
      dis play  :  flex ; 
     flex-direction  :  column  ; 
 } 
  .child-1   { 
     flex  : auto ; 
     order  :  ; 
     background  :   #000  ; 
 } 
  .child-2   { 
     flex  : auto ; 
     order  :  ; 
     background  :   rgb  ( , ,  )  ; 
 } 

 

效果 图

  <!DOCTYPE html> 
   < html   lang   =  " en "   >  
   < head  >  
       <  Meta    charset   =  " UTF-8 "   >  
       <  Meta    name   =  " viewport "    content   =  " width=device-width, initial-scale=1.0 "   >  
       <  Meta    http-equiv   =  " X-UA-Compatible "    content   =  " ie=edge "   >  
       < title  >  Document   </ title  >  
       < style  >   
         .demo   { 
      dis play  :  flex ; 
     flex-direction  :  column  ; 
 } 
  .child-1   { 
     flex  : auto ; 
     order  :  ; 
     background  :   #000  ; 
 } 
  .child-2   { 
     flex  : auto ; 
     order  :  ; 
     background  :   rgb  ( , ,  )  ; 
 } 
        </ style  >  
   </ head  >  
   < body  >  
   < div   class   =  " demo "   >  
       < div   class   =  " child-1 "   >  
        1
       </ div  >  
       < div   class   =  " child-2 "   >  
        2
       </ div  >  
   </ div  >  
   </ body  >  
   </ html  >  
 

子元素 child-1 在下 child-2 在上

6. 经验 分享

通过使用 order 属性 可以实现拖动排序,当 JS 脚本运行之后,只要确定元素拖动到指定的位置通过 修改 对应的 order 就可以轻松完成顺序的改变。

7. 小结

只有在弹性盒模型下起作用。

flex: grow、shrink、basis ? ?flex 弹性盒子布局

查看更多关于flex order 顺序的详细内容...

  阅读:44次

上一篇

下一篇

第1节:CSS3简介    第2节:border 边框    第3节:borderImage 边框图片    第4节:border-radius 圆角    第5节:box-shadow 阴影    第6节:box-sizing 盒类型    第7节:gradients 渐变    第8节:text-justify 对齐    第9节:text-overflow 文字超出    第10节:text-shadow 文本阴影    第11节:word-break 文本打断    第12节:word-wrap 文本换行    第13节:letter-spacing 字间距    第14节:perspective 透视    第15节:transform 2D 空间转换    第16节:transform 3D 空间转换    第17节:transition 过渡    第18节:animation 动画    第19节:columns 字符分割    第20节:flex 弹性盒子布局    第21节:flex order 顺序    第22节:flex: grow、shrink、basis    第23节:flex-direction 排列方向    第24节:justify-content (轴内)对齐方式    第25节:flex-wrap 换行    第26节:align-items 竖直方向对齐方式    第27节:align-content    第28节:Grid 布局简介    第29节:Grid 行和列    第30节:media 媒体查询    第31节:only 元素选择    第32节:before && after 位置    第33节:nth 类型元素选择器    第34节:calc 计算属性