0
A
回答
1
您可以用Flexbox的做(如果设置父固定的高度,例如100vh),但在这种情况下,这样做的首选方法是用电网:
* {margin:0;padding:0;box-sizing:border-box}
html, body {width:100%}
#container {
display: grid;
grid-template-columns: 1fr 1fr; /* makes two columns, can also use 50% 50%, repeat(2, 1fr) or repeat(2, 50%), fr stands for fractions */
grid-auto-rows: 150px; /* adjust or don't use at all, not mandatory */
grid-gap: 5px 0; /* adjust, atm. 5px vertical gap, 0px horizontal */
color: #fff;
font-size: 4em;
font-weight: bold;
text-align: center;
}
#container > div:nth-child(2) { /* can also use :nth-of-type(2) */
grid-column: 1; /* puts the blue one in the left column */
grid-row: 1/3; /* span two rows */
}
@media screen and (max-width: 568px) { /* adjust */
#container {
grid-template-columns: 1fr; /* makes one column, can also use 100% */
grid-gap: 0;
}
#container > div:nth-child(2) {
grid-row: 2; /* puts it back where it belongs */
}
}
<div id="container">
<div style="background: green">1</div>
<div style="background: blue">2</div>
<div style="background: red">3</div>
</div>
至于替代,您可以采取的定位优势:
* {margin:0;padding:0;box-sizing:border-box}
html, body {width:100vw;height:100vh} /* viewport units */
#container {
position: relative; /* needs to be on the parent */
height: 100%;
color: #fff;
font-size: 4em;
font-weight: bold;
text-align: center;
}
#container > div {
position: absolute; /* needs to be on the children */
}
#container > div:first-child {
top: 0;
right: 0;
width: 50%;
height: 147.5px; /* -2.5px for the vertical gap */
}
#container > div:nth-child(2) {
top: 0;
left: 0;
width: 50%;
height: 300px;
}
#container > div:nth-child(3) { /* can also use the :last-child */
top: 152.5px; /* height of the :first-child + 5px */
right: 0;
width: 50%;
height: 147.5px; /* -2.5px for the vertical gap */
}
@media screen and (max-width: 568px) {
#container > div {position:static}
#container > div:first-child,
#container > div:nth-child(2),
#container > div:nth-child(3) {
width: 100%;
height: 150px;
}
}
<div id="container">
<div style="background: green">1</div>
<div style="background: blue">2</div>
<div style="background: red">3</div>
</div>
+0
有_many_ dupe可供选择:) – LGSon
相关问题
- 1. flexbox四平铺布局
- 2. Flexbox拼贴网格布局
- 3. white-space:nowrap打破flexbox布局
- 4. 用flexbox设置布局
- 5. Flexbox布局对齐内容
- 6. Flexbox响应式布局
- 7. Flexbox 4项目布局
- 8. Doctype中断flexbox布局
- 9. Flexbox的响应行列布局
- 10. Flexbox的布局查询,行分列
- 11. “圣杯”使用flexbox的三列布局
- 12. 长文本打破我的flexbox布局
- 13. 用于页面布局的Flexbox?
- 14. 固定div的两列flexbox布局
- 15. Safari 8中的Flexbox布局突破
- 16. Flexbox的栏布局响应与列重新排序没有固定的高度
- 17. CSS Flexbox响应式布局和%宽度
- 18. 如何使用flexbox编写此布局?
- 19. Flexbox响应式布局对齐
- 20. Flexbox的布局 - 多行如果有足够长的
- 21. 在flexbox布局中叠加div div
- 22. 我如何写这个CSS Flexbox布局?
- 23. 角材料圣杯flexbox布局
- 24. 具有多个侧边栏的Flexbox响应式布局
- 25. EXT JS布局XHTML
- 26. JS条件布局
- 27. 没有布局的条件布局和动作缓存
- 28. Cytoscape布局 - 没有这样的布局可乐发现
- 29. Flexbox布局。无法将相框的宽度设置为
- 30. 删除flexbox布局中的行之间的大差距
的又一可能复制https://stackoverflow.com/questions/41790378/css-flexbox-group-2-flex-items?rq=1 – LGSon
而另一个链接到一个问题,没有一个公认的答案。也许我们这次可以找到答案,并在将来继续关联这个问题? :) – Aydin4ik
只是因为一个答案没有接受,并不意味着它不能被链接,只要链接的答案(s)有一个解决方案:) – LGSon