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

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

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

  1. .flex-container {
  2. display: flex;
  3. flex-wrap: wrap;
  4. }
  5. .flex-child {
  6. border: solid blue;
  7. }
  8. .flex-fgc {
  9. border: solid blue;
  10. }
  11. .flex-inner-gc {
  12. border: solid blue;
  13. }

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

  1. &lt;div class=&#39;flex-container&#39;&gt;
  2. &lt;div class=&#39;flex-child&#39;&gt;
  3. Mem 1
  4. &lt;/div&gt;
  5. &lt;div class=&#39;flex-fgc&#39;&gt;
  6. &lt;div&gt;
  7. Mem 2
  8. &lt;/div&gt;
  9. &lt;div class=&#39;flex-inner-gc&#39;&gt;
  10. Mem 3
  11. &lt;/div&gt;
  12. &lt;/div&gt;
  13. &lt;/div&gt;

<!-- end snippet -->

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

答案1

得分: 1

  1. float 可轻松完成这个任务。
  2. <!-- begin snippet: js hide: false console: true babel: false -->
  3. <!-- language: lang-css -->
  4. .flex-child {
  5. border: solid blue;
  6. float: left;
  7. }
  8. .flex-fgc > * {
  9. float: left;
  10. border: solid blue;
  11. }
  12. .flex-inner-gc {
  13. clear: both;
  14. }
  15. <!-- language: lang-html -->
  16. <div class='flex-container'>
  17. <div class='flex-child'>
  18. Mem 1
  19. </div>
  20. <div class='flex-fgc'>
  21. <div>
  22. Mem 2
  23. </div>
  24. <div class='flex-inner-gc'>
  25. Mem 3
  26. </div>
  27. </div>
  28. </div>
  29. <!-- end snippet -->
英文:

float can easily do this.

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

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

  1. .flex-child {
  2. border: solid blue;
  3. float: left;
  4. }
  5. .flex-fgc &gt; * {
  6. float: left;
  7. border: solid blue;
  8. }
  9. .flex-inner-gc {
  10. clear: both;
  11. }

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

  1. &lt;div class=&#39;flex-container&#39;&gt;
  2. &lt;div class=&#39;flex-child&#39;&gt;
  3. Mem 1
  4. &lt;/div&gt;
  5. &lt;div class=&#39;flex-fgc&#39;&gt;
  6. &lt;div&gt;
  7. Mem 2
  8. &lt;/div&gt;
  9. &lt;div class=&#39;flex-inner-gc&#39;&gt;
  10. Mem 3
  11. &lt;/div&gt;
  12. &lt;/div&gt;
  13. &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:

确定