今天发现:最初对百分比的概念理解是不对的,并不是对父元素相对而言的百分比,如果父元素有padding就不一样了
语言表达的不清不楚,上代码,看现象:
<!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>Document</title>
<style>
.container {
width: 500px;
height: 300px;
background-color: blanchedalmond;
padding: 20px 20px;
box-sizing: border-box;
display: flex;
}
.main {
height: 100%;
width: 50%;
background-color: blue;
}
.maina {
height: 100%;
width: 50%;
background-color: rgb(88, 88, 98);
}
</style>
</head>
<body>
<div class="container">
<div class="main"></div>
<div class="maina"></div>
</div>
</body>
</html>
百分比是相对于父元素除去padding之外的长度或高度的百分比