- 作者:霏梦
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>用户自定义元素大小的计算方式</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.box {
width: 200px;
height: 180px;
border: 6px solid black;
padding: 10px;
background-color: violet;
background-clip: content-box;
/* 重新计算大小,默认是以content-box为准 */
box-sizing: border-box;
}
.box2 {
width: 80px;
height: 120px;
background-color: red;
padding: 20px;
}
</style>
</head>
<body>
<div class="box">
<div class="box2"></div>
</div>
</body>
</html>