英文:
CSS flex-direction: row-reverse Ruins wrapping
问题
所以基本上我有这个表单,它是贝宁国旗,正如你所看到的。
我想要实现的是完全相同的复制,但是镜像,绿色在右边,黄色在蓝色上面,但是当我使用反向行时,红色会掉落到绿色下面。
以下是代码:
.flag{
position:relative;
display:flex;
flex-flow:column wrap;
width:200px;
height:150px;
border:2px solid black;
}
/* 在这里设置 flex-direction= row-reverse; */
.green{background:green;}
.yellow{background:yellow;}
.red{background:red;}
.col1{width:40%;height:100%;}
.col2{width:60%;height:50%;}
<div class=flag>
<div class='col1 green'></div>
<div class='col2 yellow'></div>
<div class='col2 red'></div>
</div>
英文:
so basically I have this form which is the Benin flag as you can see.
What i want to achieve is the exact same copy but mirrored, the green on the right with yellow on top of blue, but when i use reverse-row, the red falls off under the green instead.
here is the normal example
enter image description here
Here is the code:
.flag{
position:relative;
display:flex;
flex-flow:column wrap;
width:200px;
height:150px;
border:2px solid black;
}
>! flex-direction= row-reverse;
.green{background:green;}
.yellow{background:yellow;}
.red{background:red;}
.col1{width:40%;height:100%;}
.col2{width:60%;height:50%;}
<div class=flag>
<div class='col1 green'></div>
<div class='col2 yellow'></div>
<div class='col2 red'></div>
</div>
答案1
得分: 2
row-reverse
在你的示例中的作用是将 flex-direction
从 column
改变为 row-reverse
,所以不奇怪它不再是列流。
使用 wrap-reverse
可以反转列的包裹方向:
.flag {
position: relative;
display: flex;
flex-flow: column wrap-reverse;
width: 200px;
height: 150px;
border: 2px solid black;
}
.green {background: green;}
.yellow {background: yellow;}
.red {background: red;}
.col1 {width: 40%; height: 100%;}
.col2 {width: 60%; height: 50%;}
<div class='flag'>
<div class='col1 green'></div>
<div class='col2 yellow'></div>
<div class='col2 red'></div>
</div>
希望这有所帮助。
英文:
What row-reverse
does in your example is it changes flex-direction
from column
to row-reverse
, so it's no surprise that it's no longer in a column flow.
Use wrap-reverse
instead, to reverse the column wrapping direction:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
.flag {
position: relative;
display: flex;
flex-flow: column wrap-reverse;
width: 200px;
height: 150px;
border: 2px solid black;
}
.green {background: green;}
.yellow {background: yellow;}
.red {background: red;}
.col1 {width: 40%; height: 100%;}
.col2 {width: 60%; height: 50%;}
<!-- language: lang-html -->
<div class='flag'>
<div class='col1 green'></div>
<div class='col2 yellow'></div>
<div class='col2 red'></div>
</div>
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论