简体   繁体   English

CSS Flexbox 以 % 宽度包装项目

[英]CSS Flexbox wrap item with % width

I have flexbox with 2 elements.我有带有 2 个元素的 flexbox。 First element width is 40% of flexbox, second is 60%.第一个元素宽度是 flexbox 的 40%,第二个是 60%。 I want to wrap second element when it's width is below 600px, but if the second element is wraped I want to both elements width to 100%我想在第二个元素的宽度低于 600 像素时包装它,但如果第二个元素被包装我希望两个元素的宽度都为 100%

<div style="display: flex; flex-wrap: wrap; align-items: center;">
  <div id="text1-container" class="text-container" style="flex: 4 0 40%">
    <div id="text1" class="hide-left">
      <p></p>
    </div>
  </div>
  <div style="min-width: 600px; flex: 6 0 60%">
    <img src="" style="width: 100%;">
  </div>
</div>

Try below code试试下面的代码

 .parent { display: flex; flex-wrap: wrap; }.child1 { background-color: red; flex: 1 1 40%; }.child2 { flex: 1 1 max(60%, 600px); background-color: blue; }
 <div class="parent"> <div class="child1">child1</div> <div class="child2">child2</div> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM