3

My code is

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

Why it's look like that
My result

And not like that
What I want

I want to save display:flex; of parent and I my number of <p> items can be changing on the time

ATP
  • 2,939
  • 4
  • 13
  • 34
Hugo Levet
  • 319
  • 1
  • 9

2 Answers2

-1

Try to add to .produit_sup some flex-basis or width, like 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>
Mike Kokadii
  • 509
  • 5
  • 17
  • It's wrong for same reasons of @casraf because if I have 20

    , items will go out of `.produit_sup`. And size of a column is not fixed

    – Hugo Levet Jun 02 '21 at 13:53
-1

You can do one of the following:

  1. Remove flex from your #parent
  2. Set #parent's direction to column
  3. Set an alternate width to #parent, such as 100% or 200px.

<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;
   flex-direction: column;
   width: 200px;
}
.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>
casraf
  • 21,085
  • 9
  • 56
  • 91