I hope someone can help me, thank you.
There is a similar problem Why's CSS percentage (%) height applied to grand-child of flex element?, but it is not quite the same as my problem. My problem is: the parent element ".box" of the ".item-1" element did not set a height, why does the height percentage of ".item-1" work?
Below is the reproducing code: CodePen
<!DOCTYPE html>
<html lang="zh_CN">
<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>高度百分比-工作</title>
</head>
<body>
<style>
.wrap {
background-color: #888;
display: flex;
align-items: normal;
}
.item-1 {
background-color: pink;
width: 100px;
height: 10%;
/* Take effect height=400*10% = 40 */
/* The expected height percentage does not work, that is, the
final height of ".item-1" is 0. */
}
.item-2 {
height: 400px;
width: 200px;
background-color: skyblue;
}
</style>
<div class="wrap">
<div class="box">
<div class="item-1"></div>
<div class="item-2"></div>
</div>
</div>
</body>
</html>