【发布时间】:2021-11-25 04:58:18
【问题描述】:
我有这个结构:
.flex-container {
border: solid 1px purple;
display: flex;
}
.flex-container div {
border: solid 1px red;
padding: 20px;
margin: 20px;
height: 100px;
flex: 1 1 0%;
}
.flex-container .first {
border: solid 1px blue;
flex: 3 1 0%;
}
.first {
border: solid 1px orange;
background-color: brown;
}
.second, .third {
border: solid 1px green;
flex: 1 1 0%;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="style.css">
<title>Document</title>
</head>
<body>
<div class="flex-container">
<div class="first">
First
</div>
<div class="second">
Second
</div>
<div class="third">
Third
</div>
</div>
<div class="first">Last</div>
</body>
</html>
在我将 .flexcontainer 添加到 .flex-container .first {} 选择器之前,flex 没有应用 flex: 3 1 0%。但是使用选择器 .first 会更改框的背景,因此看起来它选择正确。发生这种情况有原因吗?我只是想看看我是否掌握了基础知识。
【问题讨论】: