4

I'm having a problem with flexbox, I'm trying to get my first .cell1 to take on the width of the 3 items inside it so it should be 300px wide so I have set this to flex: 0 0 auto and I have set .cell2 to flex: 1 so it takes up the remaining space but instead of doing this it seems to overlap .cell1 and I'm not sure why?

How can I get .cell1 to take on the width of the 3 items inside it and .cell2 to take the remaining width?

.wrap {
  display:flex;
  flex-wrap:wrap;
  width: 100%;
}

.cell1{
  display:flex;
  flex: 0 0 auto;
  flex-direction: row;
}
.cell2{
  display: flex;
  flex: 1;
  background: #ff0000;
}
.item1{
  flex: 0 0 100px;
  background: #ff0000;
}

.item2{
  flex: 0 0 100px;
  background: #0000ff;
}

.item3{
  flex: 0 0 100px;
  background: #ff00ff;
}
<div class="wrap">
  <div class="cell1">
    <div class="item1">
    item 1
    </div>
    <div class="item2">
    item 2
    </div>
    <div class="item3">
    item 3
    </div>
  </div>

  <div class="cell2">
  cell2
  </div>
</div>

0

1 Answer 1

4

Use width instead of flex-basis. This is a known bug that you can read more about here :

What are the differences between flex-basis and width? (At the end of the accepted answer by @Michael_B)

Bug affecting all major browsers, except IE 11 & Edge:

flex-basis ignored in a nested flex container. width works. A problem has been found when sizing flex items in a nested flex container.

.wrap {
  display:flex;
  flex-wrap:wrap;
  width: 100%;
}

.cell1{
  display:flex;
  flex-direction: row;
}
.cell2{
  display: flex;
  flex: 1;
  background: #ff0000;
}
.item1{
  width:100px;
  background: #ff0000;
}

.item2{
  width:100px;
  background: #0000ff;
}

.item3{
  width:100px;
  background: #ff00ff;
}
<div class="wrap">
  <div class="cell1">
    <div class="item1">
    item 1
    </div>
    <div class="item2">
    item 2
    </div>
    <div class="item3">
    item 3
    </div>
  </div>

  <div class="cell2">
  cell2
  </div>
</div>

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.