无法固定显示flex元素的顺序。

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

Can not fix the order of display:flex elements

问题

.test {
  display: flex;
  flex-direction: column;
  flex: 1;
  flex-wrap: wrap;
}

.break {
  flex-basis: 100%;
  height: 0;
}

.b {
  width: 500px;
  height: 50px;
  border: 1px solid red;
  flex-basis: 20%;
  flex-wrap: nowrap;
}

.flex1 {
  display: flex;
  flex-direction: row;
}

.test2 {
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
}

.bb {
  display: flex;
}

.flex2 {
  display: flex;
  flex-wrap: wrap;
}

.flex3 {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
}
英文:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

.test {
  display: flex;
  flex - direction: column;
  flex: 1;
  flex - wrap: wrap;
}

.break {
  flex - basis: 100 %;
  height: 0;
}

.b {
  width: 500 px;
  height: 50 px;
  border: 1 px solid red;
  flex - basis: 20 %;
  flex - wrap: nowrap;
}

.flex1 {
  display: flex;
  flex - direction: row;
}

.test2 {
  display: flex;
  flex - direction: column;
  flex - wrap: nowrap;
}

.bb {
  display: flex;
}

.flex2 {
  display: flex;
  flex - wrap: wrap;
}

.flex3 {
  display: flex;
  flex - direction: row;
  flex - wrap: wrap;
  align - items: center;
}

<!-- language: lang-html -->

&lt;div class=&quot;test&quot;&gt;
  &lt;div class=&quot;flex1&quot;&gt;
    &lt;div class=&quot;1 b&quot;&gt;1&lt;/div&gt;
    &lt;div class=&quot;2 b&quot;&gt;1&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class=&quot;test2&quot;&gt;
    &lt;div class=&quot;flex2&quot;&gt;
      &lt;div class=&quot;3 b&quot;&gt;2.1&lt;/div&gt;
      &lt;div class=&quot;4 b&quot;&gt;2.2&lt;/div&gt;
      &lt;div class=&quot;break&quot;&gt;&lt;/div&gt;
      &lt;div class=&quot;5 b bb&quot;&gt;2.3&lt;/div&gt;
    &lt;/div&gt;

    &lt;div class=&quot;flex3&quot;&gt;
      &lt;div class=&quot;3 b bb&quot;&gt;3.1&lt;/div&gt;
      &lt;div class=&quot;break&quot;&gt;&lt;/div&gt;
      &lt;div class=&quot;4 b&quot;&gt;3.2&lt;/div&gt;
      &lt;div class=&quot;break&quot;&gt;&lt;/div&gt;
      &lt;div class=&quot;5 b&quot;&gt;3.3&lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

<!-- end snippet -->

I have a problem with a display:flex when ordering the elements. I want to achieve the same thing as in the image . I want the 3.1 to be in the same row as the 2.3 and the 3.2 and the 3.3 to stay exactly the same as in the image.

Here is the image example that I want to achieve

I want to achieve this behavior in the media queries, the HTML order should stay the same.

答案1

得分: 0

希望能帮助

<!-- 开始代码段: js 隐藏: false 控制台: true Babel: false -->

<!-- 语言: lang-css -->
.row {
  display: flex;
  gap: 30px;
}

.item {
  flex: 0 0 40%;
  padding: 10px;
  border: 1px solid red;
}

.column>div {
  width: 40%;
}

<!-- 语言: lang-html -->
<div class="container">
  <div class="row">
    <div class="item">1</div>
    <div class="item">1</div>
  </div>
  <div class="row">
    <div class="item">2.1</div>
    <div class="item">2.2</div>
  </div>
  <div class="row">
    <div class="item">2.3</div>
    <div class="item">3.1</div>
  </div>
  <div class="column">
    <div class="item">3.2</div>
    <div class="item">3.3</div>
  </div>
</div>

<!-- 结束代码段 -->
英文:

Hope it helps

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

.row {
  display: flex;
  gap: 30px;
}

.item {
  flex: 0 0 40%;
  padding: 10px;
  border: 1px solid red;
}

.column&gt;div {
  width: 40%;
}

<!-- language: lang-html -->

&lt;div class=&quot;container&quot;&gt;
  &lt;div class=&quot;row&quot;&gt;
    &lt;div class=&quot;item&quot;&gt;1&lt;/div&gt;
    &lt;div class=&quot;item&quot;&gt;1&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class=&quot;row&quot;&gt;
    &lt;div class=&quot;item&quot;&gt;2.1&lt;/div&gt;
    &lt;div class=&quot;item&quot;&gt;2.2&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class=&quot;row&quot;&gt;
    &lt;div class=&quot;item&quot;&gt;2.3&lt;/div&gt;
    &lt;div class=&quot;item&quot;&gt;3.1&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class=&quot;column&quot;&gt;
    &lt;div class=&quot;item&quot;&gt;3.2&lt;/div&gt;
    &lt;div class=&quot;item&quot;&gt;3.3&lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年7月27日 22:32:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/76780781.html
匿名

发表评论

匿名网友

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

确定