盒模型由四个部分组成:
标准盒模型大小 = border + padding + content
怪异盒模型大小 = content
转怪异盒模型:box-sizing:border-box;
转标准盒模型:box-sizing:content-box;
怪异盒模型也叫 IE 盒子模型
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Documenttitle>
<style>
.outer {
width: 100px;
height: 100px;
color: #f00;
border: 5px solid #000;
padding: 10px;
margin-top: 20px;
}
style>
head>
<body>
<div class="outer">
hello
div>
<div style="width: 100px;height: 1px;background-color: #f00;margin-top: 10px;">div>
body>
html>

我们设置了宽高 100*100px,但是我们可以看到明显比红线的 100px 要长一些,因为现在的盒子是标准盒子模型,所以盒子的宽是:
100(content)+10(padding)+5(border)= 115px
实际工作中,其实我觉得怪异盒子模型更加实用,比如设计稿给你一个宽度 100px,padding 10px 的一个设计。我可以直接去写css代码:
// 转换为怪异盒子模型
box-sizing:border-box;
width: 100px;
padding: 10px;
如果使用标准盒子,我就要去计算这个宽度设置为 80,而不是直接用设计稿给的 100,这样就非常的麻烦
width: 80px;
padding: 10px;