Here is one way of achieving the layout, I strongly advise, if you can, to use CSS Grid instead.
(这是一种实现布局的方法,如果可能的话,我强烈建议改用CSS Grid。)
.grid { display: flex; flex: 1; } .grid--col { flex-direction: column; } .grid__item { display: flex; justify-content: center; align-items: center; flex: 1; border: 1px solid #ddd; } .grid__item--x2 { flex: 2; } .grid--main { background: #f5f5f5; border: 1px dashed #999; max-width: 960px; margin: 50px auto; }
<div class="grid grid--main"> <div class="grid__item">1</div> <div class="grid__item grid__item--x2"> <div class="grid grid--col"> <div class="grid"> <div class="grid__item">2</div> <div class="grid__item grid__item--x2">4</div> <div class="grid__item">8</div> </div> <div class="grid"> <div class="grid__item">3</div> <div class="grid__item">5</div> <div class="grid__item">6</div> <div class="grid__item">7</div> </div> </div> </div> </div>
You can modify the CSS/SCSS code to change the layout for different breakpoints using the CSS @media rules.
(您可以使用CSS @media规则修改CSS / SCSS代码以更改不同断点的布局。)
For example, you can have everything stacked, when the viewport is less than or equal to 960px.
(例如,当视口小于或等于960px时,您可以堆叠所有内容。)
@media only screen and (max-width: 960px) {
.grid {
flex-direction: column;
}
}
.grid { display: flex; flex: 1; } .grid--col { flex-direction: column; } .grid__item { display: flex; justify-content: center; align-items: center; flex: 1; border: 1px solid #ddd; } .grid__item--x2 { flex: 2; } .grid--main { background: #f5f5f5; border: 1px dashed #999; max-width: 960px; margin: 50px auto; } @media only screen and (max-width: 960px) { .grid { flex-direction: column; } }
<div class="grid grid--main"> <div class="grid__item">1</div> <div class="grid__item grid__item--x2"> <div class="grid grid--col"> <div class="grid"> <div class="grid__item">2</div> <div class="grid__item grid__item--x2">4</div> <div class="grid__item">8</div> </div> <div class="grid"> <div class="grid__item">3</div> <div class="grid__item">5</div> <div class="grid__item">6</div> <div class="grid__item">7</div> </div> </div> </div> </div>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…