简体   繁体   English

FlexBox:同一列上有 2 个元素,而 flex-direction 列

[英]FlexBox: 2 Elements on the same column while flex-direction column

I have a container with 3 elements that together share a width of 100% (25%,50%,25%).我有一个包含 3 个元素的容器,它们的宽度共同为 100%(25%、50%、25%)。 If the container has less than 800px the order of the elements should be changed.如果容器小于 800 像素,则应更改元素的顺序。 #box2 has a width of 100%. #box2 的宽度为 100%。 #box1 and #box3 should both have a width of 50% and be on the same column. #box1 和#box3 的宽度都应该是 50%,并且在同一列上。 So as a final result I should have one column with #box2 at 100% and a second column with #box1 and #box2 at 50%.因此,作为最终结果,我应该有一列#box2 为 100%,第二列#box1 和#box2 为 50%。 How do I get #box1 and #box3 to be in the same column in the code below?如何让#box1 和#box3 在下面的代码中位于同一列中?

JsFiddle (link) JsFiddle(链接)

 #container { display: flex; flex-direction: row; max-width: 100vw; width: 100%; } #box1 { background: yellow; width: 25%; } #box2 { background: orange; width: 50%; } #box3 { background: red; width: 25%; } /* Large Ansicht */ @media only screen and (max-width: 800px) { #container { flex-direction: column; } #box1 { background: yellow; width: 50%; order: 2; } #box2 { background: orange; width: 100%; order: 1; } #box3 { background: red; width: 50%; order: 3; } }
 <div id="container"> <div id="box1">sidemenu</div> <div id="box2">app</div> <div id="box3">sidemenu 2</div> </div>

You could replace flex-direction: column;你可以替换flex-direction: column; with flex-wrap: wrap;使用flex-wrap: wrap; : :

 #container { display: flex; flex-direction: row; max-width: 100vw; width: 100%; } #box1 { background: yellow; width: 25%; } #box2 { background: orange; width: 50%; } #box3 { background: red; width: 25%; } /* Large Ansicht */ @media only screen and (max-width: 800px) { #container { flex-wrap: wrap; } #box1 { background: yellow; width: 50%; order: 2; } #box2 { background: orange; width: 100%; order: 1; } #box3 { background: red; width: 50%; order: 3; } }
 <div id="container"> <div id="box1">sidemenu</div> <div id="box2">app</div> <div id="box3">sidemenu 2</div> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM