我试着用柔性盒构建这样的布局:

我如何将这些项目堆叠在一起?
我使用CSS网格构建了上面的屏幕截图,但是没有使用flexbox来实现。
.grid {
display: grid;
height: 100%;
grid-template-columns: 2rem repeat(2, auto) 2rem;
grid-template-rows: 4rem 4rem auto;
background-color: #fff;
}
.layer1 {
background-color: rgb(64, 213, 187);
grid-column-start: 1;
grid-column-end: span 3;
grid-row-start: 1;
grid-row-end: span 3;
}发布于 2017-05-03 12:13:46
注意:这个问题是关于沿着z轴__堆叠弹性项的问题。如果您来这里是为了寻找沿着y-axis__的“互相堆叠的挠曲项目”,请参阅下面的文章:https://stackoverflow.com/q/42723596/3597276。
Flexbox设计用于对齐列或行中的元素。它不是为堆叠而设计的。
然而,CSS网格对于这类事情来说是完美的。
CSS替代网格的方法是绝对定位:
(请注意,当一个flex项目是绝对定位的时,它不再接受大多数flex属性。)
article {
display: flex;
height: 100vh;
position: relative;
}
section:nth-child(1) {
flex: 1;
background-color: turquoise;
}
section:nth-child(2) {
position: absolute;
top: 50px;
left: 50px;
right: 0;
bottom: 0;
background-color: salmon;
}
section:nth-child(3) {
position: absolute;
top: 100px;
left: 250px;
right: 0;
bottom: 0;
background-color: thistle;
}
body {
margin: 0;
}<article>
<section></section>
<section></section>
<section></section>
</article>
https://stackoverflow.com/questions/43759195
复制相似问题