flex兼容性写法

一.W3C各个版本的flex

2009 version

标志:display: box; or a property that is box-{*} (eg. box-pack)

2011 version

标志:display: flexbox; or the flex() function or flex-pack property

2012 version

标志:display: flex/inline-flex; and flex-{*} properties

2014 version

新增了对flex项z-index的规定

2015 W3C Editor’s Draft

没有大的改动

P.S.注意2015的是W3C Editor’s Draft,只是个草案,还处于修修改改的阶段,还没有征集浏览器供应商的意见

二.浏览器兼容性

关于flex的W3C规范:http://dev.w3.org/csswg/css-flexbox-1/

浏览器兼容性可以参考CanIUse:http://caniuse.com/#feat=flexbox

根据CanIUse的数据可以总结如下:

IE10部分支持2012,需要-ms-前缀

Android4.1/4.2-4.3部分支持2009,需要-webkit-前缀

Safari7/7.1/8部分支持2012,需要-webkit-前缀

iOS Safari7.0-7.1/8.1-8.3部分支持2012,需要-webkit-前缀

所以需要考虑新版本2012:http://www.w3.org/TR/2012/CR-css3-flexbox-20120918/

而Android需要考虑旧版本2009:http://www.w3.org/TR/2009/WD-css3-flexbox-20090723/

三.浏览器兼容的flex语法

[javascript] view plain copy 在CODE上查看代码片派生到我的代码片
/* 子元素-平均分栏 */

.flex1 {  
    -webkit-box-flex: 1;      /* OLD - iOS 6-, Safari 3.1-6 */  
    -moz-box-flex: 1;         /* OLD - Firefox 19- */  
    width: 20%;               /* For old syntax, otherwise collapses. */  
    -webkit-flex: 1;          /* Chrome */  
    -ms-flex: 1;              /* IE 10 */  
    flex: 1;                  /* NEW, Spec - Opera 12.1, Firefox 20+ */  
}  

/* 父元素-横向排列(主轴) */

.flex-h {  
    display: box;              /* OLD - Android 4.4- */  

    display: -webkit-box;      /* OLD - iOS 6-, Safari 3.1-6 */  
    display: -moz-box;         /* OLD - Firefox 19- (buggy but mostly works) */  
    display: -ms-flexbox;      /* TWEENER - IE 10 */  
    display: -webkit-flex;     /* NEW - Chrome */  
    display: flex;             /* NEW, Spec - Opera 12.1, Firefox 20+ */  


    /* 09版 */  
    -webkit-box-orient: horizontal;  
    /* 12版 */  
    -webkit-flex-direction: row;  
    -moz-flex-direction: row;  
    -ms-flex-direction: row;  
    -o-flex-direction: row;  
    flex-direction: row;  
}  

/* 父元素-横向换行 */

.flex-hw {  
    /* 09版 */  
    /*-webkit-box-lines: multiple;*/  
    /* 12版 */  
    -webkit-flex-wrap: wrap;  
    -moz-flex-wrap: wrap;  
    -ms-flex-wrap: wrap;  
    -o-flex-wrap: wrap;  
    flex-wrap: wrap;  
}  

/* 父元素-水平居中(主轴是横向才生效) */

.flex-hc {  
    /* 09版 */  
    -webkit-box-pack: center;  
    /* 12版 */  
    -webkit-justify-content: center;  
    -moz-justify-content: center;  
    -ms-justify-content: center;  
    -o-justify-content: center;  
    justify-content: center;  
    /* 其它取值如下: 
        align-items     主轴原点方向对齐 
        flex-end        主轴延伸方向对齐 
        space-between   等间距排列,首尾不留白 
        space-around    等间距排列,首尾留白 
     */  
}  

/* 父元素-纵向排列(主轴) */

.flex-v {  
    display: box;              /* OLD - Android 4.4- */  

    display: -webkit-box;      /* OLD - iOS 6-, Safari 3.1-6 */  
    display: -moz-box;         /* OLD - Firefox 19- (buggy but mostly works) */  
    display: -ms-flexbox;      /* TWEENER - IE 10 */  
    display: -webkit-flex;     /* NEW - Chrome */  
    display: flex;             /* NEW, Spec - Opera 12.1, Firefox 20+ */  


    /* 09版 */  
    -webkit-box-orient: vertical;  
    /* 12版 */  
    -webkit-flex-direction: column;  
    -moz-flex-direction: column;  
    -ms-flex-direction: column;  
    -o-flex-direction: column;  
    flex-direction: column;  
}  

/* 父元素-纵向换行 */

.flex-vw {  
    /* 09版 */  
    /*-webkit-box-lines: multiple;*/  
    /* 12版 */  
    -webkit-flex-wrap: wrap;  
    -moz-flex-wrap: wrap;  
    -ms-flex-wrap: wrap;  
    -o-flex-wrap: wrap;  
    flex-wrap: wrap;  
}  

/* 父元素-竖直居中(主轴是横向才生效) */

.flex-vc {  
    /* 09版 */  
    -webkit-box-align: center;  
    /* 12版 */  
    -webkit-align-items: center;  
    -moz-align-items: center;  
    -ms-align-items: center;  
    -o-align-items: center;  
    align-items: center;  
}  

/* 子元素-显示在从左向右(从上向下)第1个位置,用于改变源文档顺序显示 */

.flex-1 {  
    -webkit-box-ordinal-group: 1;   /* OLD - iOS 6-, Safari 3.1-6 */  
    -moz-box-ordinal-group: 1;      /* OLD - Firefox 19- */  
    -ms-flex-order: 1;              /* TWEENER - IE 10 */  
    -webkit-order: 1;               /* NEW - Chrome */  
    order: 1;                       /* NEW, Spec - Opera 12.1, Firefox 20+ */  
}  

/* 子元素-显示在从左向右(从上向下)第2个位置,用于改变源文档顺序显示 */

.flex-2 {  
    -webkit-box-ordinal-group: 2;   /* OLD - iOS 6-, Safari 3.1-6 */  
    -moz-box-ordinal-group: 2;      /* OLD - Firefox 19- */  
    -ms-flex-order: 2;              /* TWEENER - IE 10 */  
    -webkit-order: 2;               /* NEW - Chrome */  
    order: 2;                       /* NEW, Spec - Opera 12.1, Firefox 20+ */  
}  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值