flex 属性加上之后 padding 依然会撑大盒子,使用 box-sizing: border-box 可以不改变原来盒子的大小
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
div{
width: 200px;
height: 200px;
background-color: red;
display: flex;
padding: 20px;
box-sizing: border-box;
}
</style>
</head>
<body>
<div></div>
</body>
</html>