CSS3 box-sizing屬性

box-sizing屬性能夠爲三個值之一:content-box(default),border-box,padding-box。css

content-box,border和padding不計算入width以內android

padding-box,padding計算入width內ios

border-box,border和padding計算入width以內,其實就是怪異模式了~web

 

ie8+瀏覽器支持content-box和border-box;瀏覽器

ff則支持所有三個值。spa

 

使用時:code

-webkit-box-sizing: 100px; // for ios-safari, androidblog

-moz-box-sizing:100px; //for ffit

box-sizing:100px; //for otherio

栗子:

複製代碼
<style type="text/css">
    .content-box{
        box-sizing:content-box;
        -moz-box-sizing:content-box;
        width: 100px;
        height: 100px;
        padding: 20px;
        border: 5px solid #E6A43F;
        background: blue;
    }
    .padding-box{
        box-sizing:padding-box;
        -moz-box-sizing:padding-box;
        width: 100px;
        height: 100px;
        padding: 20px;
        border: 5px solid #186645;
        background: red;                
    }
    .border-box{
        box-sizing:border-box;
        -moz-box-sizing:border-box;
        width: 100px;
        height: 100px;
        padding: 20px;
        border: 5px solid #3DA3EF;
        background: yellow;
    }
</style>
複製代碼

截圖(ff):

相關文章
相關標籤/搜索