如何使用 flexbox 将嵌套 div 结构中的内部 div 放在新行上?

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

How to get the inner div of the nested div structure into the new line using flex box?

问题

I want the inner div (Mem 3) in the new line, just below Mem 1, and I do not want to change the div structure at any cost. Please help.

Like this => 如何使用 flexbox 将嵌套 div 结构中的内部 div 放在新行上?


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

.flex-child {
border: solid blue;
}

.flex-fgc {
border: solid blue;
}

.flex-inner-gc {
border: solid blue;
}

Mem 1
Mem 2
Mem 3

I tried 'flex: 1 1 100;' for the flex-inner-gc.

英文:

如何使用 flexbox 将嵌套 div 结构中的内部 div 放在新行上?

I want the inner div (Mem 3) in the new line, just below Mem 1, and I do not want to change the div structure at any cost. Please help.

Like this => 如何使用 flexbox 将嵌套 div 结构中的内部 div 放在新行上?

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

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

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

.flex-child {
  border: solid blue;
}

.flex-fgc {
  border: solid blue;
}

.flex-inner-gc {
  border: solid blue;
}

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

&lt;div class=&#39;flex-container&#39;&gt;
  &lt;div class=&#39;flex-child&#39;&gt;
    Mem 1
  &lt;/div&gt;
  &lt;div class=&#39;flex-fgc&#39;&gt;
    &lt;div&gt;
      Mem 2
    &lt;/div&gt;
    &lt;div class=&#39;flex-inner-gc&#39;&gt;
      Mem 3
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

<!-- end snippet -->

I tried 'flex: 1 1 100;' for the flex-inner-gc.

答案1

得分: 1

float 可轻松完成这个任务。

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

<!-- language: lang-css -->
.flex-child {
  border: solid blue;
  float: left;
}

.flex-fgc > * {
  float: left;
  border: solid blue;
}

.flex-inner-gc {
  clear: both;
}

<!-- language: lang-html -->
<div class='flex-container'>
  <div class='flex-child'>
    Mem 1
  </div>
  <div class='flex-fgc'>
    <div>
      Mem 2
    </div>
    <div class='flex-inner-gc'>
      Mem 3
    </div>
  </div>
</div>

<!-- end snippet -->
英文:

float can easily do this.

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

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

.flex-child {
  border: solid blue;
  float: left;
}

.flex-fgc &gt; * {
  float: left;
  border: solid blue;
}

.flex-inner-gc {
  clear: both;
}

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

&lt;div class=&#39;flex-container&#39;&gt;
  &lt;div class=&#39;flex-child&#39;&gt;
    Mem 1
  &lt;/div&gt;
  &lt;div class=&#39;flex-fgc&#39;&gt;
    &lt;div&gt;
      Mem 2
    &lt;/div&gt;
    &lt;div class=&#39;flex-inner-gc&#39;&gt;
      Mem 3
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

<!-- end snippet -->

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

发表评论

匿名网友

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

确定