html - 为什么 column 和 wrap 中的 flexbox 坏了

标签 html css flexbox

<分区>

我的代码是

<div id="parent">
   <div class="produit_sup">
      <p>Aubergine</p>
      <p>Betterave</p>
      <p>Courgette</p>
      <p>Oignon</p>
      <p>Poireau</p>
      <p>Pomme de terre</p>
      <p>Tomate</p>
   </div>
</div>

<style>
#parent{
   display: flex;
}
.produit_sup{
   max-height: 100px;
   background: #c3c3ff;
   display: flex;
   flex-direction: column;
   flex-wrap: wrap;
}
.produit_sup>p{
   width: 100px;
   text-align: left;
   margin: 0 20px 0 0;
}
</style>

为什么会这样
My result

不是那样的
What I want

我要保存display:flex; parent 和我的号码 <p>元素可以随时更改

最佳答案

尝试向 .produit_sup 添加一些 flex-basiswidth,例如 width:50%

<div id="parent">
   <div class="produit_sup">
      <p>Aubergine</p>
      <p>Betterave</p>
      <p>Courgette</p>
      <p>Oignon</p>
      <p>Poireau</p>
      <p>Pomme de terre</p>
      <p>Tomate</p>
   </div>
</div>

<style>
#parent{
   display: flex;
}
.produit_sup{
   width: 50%;
   max-height: 100px;
   background: #c3c3ff;
   display: flex;
   flex-direction: column;
   flex-wrap: wrap;
}
.produit_sup>p{
   width: 100px;
   margin: 0 20px 0 0;
}
</style>

关于html - 为什么 column 和 wrap 中的 flexbox 坏了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67806168/

相关文章:

html - DIvs 中的垂直滚动内容 - 重新加载到顶部

css - 在 CSS Flexbox 中,为什么没有 "justify-items"和 "justify-self"属性?

css - 悬停时的圆形按钮动画 - 边框移动效果

css - 对齐 flex 父项列表中的子项

javascript - 使用 jQuery : How can a value be updated to match an elements visibility?

javascript - 在javascript中添加一个正方形

javascript - 如何更改此 Javascript 代码中的表格元素?

css - 如何在 react Bootstrap 中的工具提示内放置换行符?

css - 使用flexbox调整图片高度

angular - 如何在 Angular 7 中配置 Autoprefixer