.xiangmin {
    width: 100%;
    height: 100%;
    display: -moz-box;
    display: -webkit-box;
    display: -ms-flexbox;
    display: -o-box;
    display: box;
    -moz-box-orient: horizontal;
    -moz-box-pack: center;
    -moz-box-align: center;
    -webkit-box-orient: horizontal;
    -webkit-box-pack: center;
    -webkit-box-align: center;
    -ms-flex-align: center;
    -ms-flex-pack: center;
    -ms-box-orient:horizontal;
    -o-box-orient: horizontal;
    -o-box-pack: center;
    -o-box-align: center;
    box-orient: horizontal;
    box-pack: center;
    box-align: center;
}

这段代码于2013年5月9日通过了所有现代浏览器(IE9以下、国产壳浏览器除外)的测试。

另外值得一提的是:flexbox是标准,普通的-*-box或box是要淘汰的,所以尽量不要再用box了。

 

昨天貌似火狐更新了,不知为何代码失效了,故今天(2013年5月14日)将代码更新为flexbox版本!

    // start of flex box
    .flexbox {
        width: 100%;
        height: 100%;
        display: -webkit-box;
        display: -moz-box;
        display: -ms-flexbox;
        display: -webkit-flex;
        display: flex;
        -webkit-box-direction: normal;
        -moz-box-direction: normal;
        -webkit-box-orient: vertical;
        -moz-box-orient: vertical;
        -webkit-flex-direction: column;
        -ms-flex-direction: column;
        flex-direction: column;
        -webkit-flex-wrap: nowrap;
        -ms-flex-wrap: nowrap;
        flex-wrap: nowrap;
        -webkit-box-pack: center;
        -moz-box-pack: center;
        -webkit-justify-content: center;
        -ms-flex-pack: center;
        justify-content: center;
        -webkit-align-content: stretch;
        -ms-flex-line-pack: stretch;
        align-content: stretch;
        -webkit-box-align: center;
        -moz-box-align: center;
        -webkit-align-items: center;
        -ms-flex-align: center;
        align-items: center;
    }

    .flex div {
        -webkit-box-ordinal-group: 1;
        -moz-box-ordinal-group: 1;
        -webkit-order: 0;
        -ms-flex-order: 0;
        order: 0;
        -webkit-box-flex: 0;
        -moz-box-flex: 0;
        -webkit-flex: 0 1 auto;
        -ms-flex: 0 1 auto;
        flex: 0 1 auto;
        -webkit-align-self: auto;
        -ms-flex-item-align: auto;
        align-self: auto;
    }
    @-moz-document url-prefix() {
    .flexbox {
        width: 100%;
        -moz-box-sizing: border-box;
        }
    }
    // end of flex box

最后附上一张flexbox的兼容表:http://caniuse.com/flexbox

Posted on 2013-05-09 14:48  向民  阅读(441)  评论(0编辑  收藏  举报