css3 box-sizing属性
box-sizing属性可以为三个值之一:content-box(default),border-box,padding-box。
content-box,border和padding不计算入width之内
padding-box,padding计算入width内
border-box,border和padding计算入width之内,其实就是怪异模式了~
ie8+浏览器支持content-box和border-box;
ff则支持全部三个值。
使用时:
-webkit-box-sizing: 100px; // for ios-safari, android
-moz-box-sizing:100px; //for ff
box-sizing:100px; //for other
栗子:
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style> *{ box-sizing:border-box; } .content{ width:300px; height:300px; background-color:red;} .aside{ width:100px; height:200px; background-color:green; float:left; } .article{ width:200px; height:200px; background-color:blue; float:right; border:50px solid #ccc; padding:5px; }.section{ position:fixed; left:400px; top:10px; border:1px solid black; width:100px; height:100px; float:right; background-color:yellow; } </style> </head> <body> <div class="content"> <div class="aside">aside</div> <div class="article">article</div> </div> <div class="section">section</div> </body> </html>
截图(ff):