css3 box-sizing属性

首先copy过来w3c的理论概念:

202432_o3bB_2460998.png

    w3c里的box-sizing的值只写了俩个,但是我查了以后发现有三个值;

    box-sizing属性可以为三个值:content-box(default),border-box,padding-box。

    1.content-box,border和padding不计算入width之内

    这是标准的W3C的标准Box Model,如图:

    203759_ANjM_2460998.jpg

       

/*外盒尺寸计算(元素空间尺寸)*/
  Element空间高度 = content height + padding + border + margin
  Element 空间宽度 = content width + padding + border + margin
  /*内盒尺寸计算(元素大小)*/
  Element Height = content height + padding + border (Height为内容高度)
  Element Width = content width + padding + border (Width为内容宽度)

    2.border-box,border和padding计算入width之内,其实就是怪异模式了,

       这是IE的传统模型(IE6以下,不含IE6版本或“QuirksMode下IE5.5+”)

204408_hzld_2460998.jpg

         

 /*外盒尺寸计算(元素空间尺寸)*/
  Element空间高度 = content Height + margin (Height包含了元素内容宽度,边框宽度,内距宽度)
  Element空间宽度 = content Width + margin (Width包含了元素内容宽度、边框宽度、内距宽度)
  /*内盒尺寸计算(元素大小)*/
  Element Height = content Height(Height包含了元素内容宽度,边框宽度,内距宽度)
  Element Width = content Width(Width包含了元素内容宽度、边框宽度、内距宽度)
  /* content*/
  content height =content +padding+border;
  conten width =content +padding +border;

        ie8+浏览器支持content-box和border-box;

        ff则支持全部三个值。

        使用时:

        -webkit-box-sizing: 100px; 

        -moz-box-sizing:100px; 

        box-sizing:100px; 

        3.padding-box,padding计算入width内   //这个一般不太用使用的

/*外盒尺寸计算(元素空间尺寸)*/
  Element空间高度 = content height  + border + margin
  Element 空间宽度 = content width  + border + margin
  /*内盒尺寸计算(元素大小)*/
  Element Height = content height + border (Height为内容高度)
  Element Width = content width + border (Width为内容宽度)
  /* content 的大小*/
  content height =content + padding;
  content width =coontent +padding;

        

        4.关于content-box与border-box的使用分析:

        在布局和form表单的使用上,

        这里有篇博文有详细的写:http://www.w3cplus.com/content/css3-box-sizing

         当然我写的大多都是通过看w3cplus然后自己写的,哈哈哈!不算copy


转载于:https://my.oschina.net/u/2460998/blog/615918

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值