CSS flex-direction: row-reverse 破坏了换行。

huangapple go评论78阅读模式
英文:

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;
}

&gt;! flex-direction= row-reverse;

.green{background:green;}
.yellow{background:yellow;}
.red{background:red;}

.col1{width:40%;height:100%;}
.col2{width:60%;height:50%;}
&lt;div class=flag&gt;
 &lt;div class=&#39;col1 green&#39;&gt;&lt;/div&gt;
 &lt;div class=&#39;col2 yellow&#39;&gt;&lt;/div&gt;
 &lt;div class=&#39;col2 red&#39;&gt;&lt;/div&gt;
&lt;/div&gt;

答案1

得分: 2

row-reverse 在你的示例中的作用是将 flex-directioncolumn 改变为 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 -->

&lt;div class=&#39;flag&#39;&gt;
 &lt;div class=&#39;col1 green&#39;&gt;&lt;/div&gt;
 &lt;div class=&#39;col2 yellow&#39;&gt;&lt;/div&gt;
 &lt;div class=&#39;col2 red&#39;&gt;&lt;/div&gt;
&lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年6月9日 08:40:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/76436516.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定