5

When I use flex-flow: column wrap, the parent element's width is not stretched.

now

expect

*{
            margin: 0;
            padding: 0;
        }
        .box{
            background: #f03;
            position: relative;
            display: inline-block;
            /* top:10px; */
            /* left: 10px; */
            padding: 20px;
        }
        .in{
            display: flex;
            align-items: center;
            flex-flow: column wrap;
            max-height: 300px; 
            align-content: flex-start;
            justify-content: space-between;

        }
        .item{
            background: #fe3;
            width: 100px;
            margin-bottom: 20px;
            height: 100px;

        }
        .item:last-child{
            margin-left: 15px;
        }
    <body>
     <div class="box">
         <div class="in">
             <div class="item">1</div>
             <div class="item">2</div>
             <div class="item">3</div>
         </div>
     </div>
</body>

https://jsfiddle.net/p4oLk7dz/5/


So what should I do?
Michael Benjamin
  • 346,931
  • 104
  • 581
  • 701
user3579659
  • 63
  • 1
  • 8

2 Answers2

-1
Remove the display properties from this class 
.box{
            background: #f03;
            display: inline-block;
           display:relative;
            /* top:10px; */
            /* left: 10px; */
            padding: 20px;
      }

and everything works !!!

*{
            margin: 0;
            padding: 0;
        }
        .box{
            background: #f03;
            padding: 20px;
        }
        .in{
            display: flex;
            align-items: center;
            flex-flow: column wrap;
            max-height: 300px; 
            align-content: flex-start;
            justify-content: space-between;

        }
        .item{
            background: #fe3;
            width: 100px;
            margin-bottom: 20px;
            height: 100px;

        }
        .item:last-child{
            margin-left: 15px;
        }
    <body>
     <div class="box">
         <div class="in">
             <div class="item">1</div>
             <div class="item">2</div>
             <div class="item">3</div>
         </div>
     </div>
</body>

you can check the result here https://jsfiddle.net/p4oLk7dz/30/

Friday Ameh
  • 1,664
  • 1
  • 10
  • 15
-1

You are trying to have a flex container inside the oder one, the first one needs the display flex to get the content of the element below

I would also make some small changes but it really depends on what you are trying to achive.

If this isnt what you were looking for, please comment so i can try to improve it. Hope this works :)

.box{
                background: #f03;
                position: relative;
                display: flex;
                max-width: 220px;
                padding: 20px;
            }
            .in{
                  display: flex;
                  flex-wrap: wrap;
                  max-width: 220px;
            }

*{
                margin: 0;
                padding: 0;
            }
            .box{
                background: #f03;
                position: relative;
                display: flex;
                max-width: 220px;
                padding: 20px;
            }
            .in{
                  display: flex;
                  flex-wrap: wrap;
                  max-width: 220px;
            }
            .item{
                background: #fe3;
                width: 100px;
                margin-bottom: 20px;
                height: 100px;
                
            }
            .item-2{
                 order: 3;
            }
            .item-3{
                 margin-left: 20px;
            }
    <body>
         <div class="box">
             <div class="in">
                 <div class="item">1</div>
                 <div class="item item-2">2</div>
                 <div class="item item-3">3</div>
             </div>
         </div>
    </body>
    <!-- 第三个并没有把父元素宽度撑开 -->
Gerardo BLANCO
  • 5,590
  • 1
  • 16
  • 35