【发布时间】:2021-12-03 04:31:29
【问题描述】:
我有这个代码:
.parent {
display: flex;
flex-direction: column;
flex-wrap: wrap;
justify-content: flex-start;
align-items: flex-start;
align-content: flex-start;
width: 200px;
height: 200px;
}
.child,
.child:not(:nth-child(1)) {
width: 100px;
height: 100px;
}
.child:last-child:nth-child(1) {
width: 200px;
height: 200px;
}
.child:nth-child(1),
.child:last-child:nth-child(2) {
width: 100px;
height: 200px;
}
.child:nth-last-child(4) {
width: 100px;
height: 100px;
}
Test with 1 children
<div class="parent" style="background-color:yellow;">
<div class="child" style="background-color:red;">1</div>
</div>
Test with 2 children
<div class="parent" style="background-color:yellow;">
<div class="child" style="background-color:red;">1</div>
<div class="child" style="background-color:blue;">2</div>
</div>
Test with 3 children
<div class="parent" style="background-color:yellow;">
<div class="child" style="background-color:red;">1</div>
<div class="child" style="background-color:blue;">2</div>
<div class="child" style="background-color:green;">3</div>
</div>
Test with 4 children
<div class="parent" style="background-color:yellow;">
<div class="child" style="background-color:red;">1</div>
<div class="child" style="background-color:blue;">2</div>
<div class="child" style="background-color:green;">3</div>
<div class="child" style="background-color:orange;">4</div>
</div>
但我希望最后一个示例有不同的顺序,即:
1 2
3 4
重要的是我不能为每个 flex 孩子添加不同的类。 Twitter 库的行为类似,但那里更复杂(它是 flex 中的 flex,可能还有一些 JS,尽管它的工作方式可能不同)。 我需要上述所有案例同时工作。
【问题讨论】:
标签: html css flexbox css-selectors