W
W
weranda2020-09-15 10:12:59
css
weranda, 2020-09-15 10:12:59

Why do nested flex items not respect the size of their parent container?

Greetings.
There is a simple example: https://codepen.io/weranda/pen/QWNBLge

<div class="wrap">
  <div class="item">1</div>
  <div class="item">2</div>
  <div class="item">3</div>
</div>

.wrap{
  display: flex;
  flex-basis: 60%;
}

.item{
  flex-basis: 33.333%;

}

Logically, the parent container should occupy 60% of the width of the window, and nested in it - 33.3% of the width of the parent container, but this does not happen. Nested containers somehow increase the width of the parent container.
Why is this happening and how can it be fixed?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pavel Shvedov, 2020-09-15
@weranda

use width for .wrap, there is a feeling that flex-basis works on elements inside a flex container, and your wrap is not wrapped by any container with display: flex;

P
Pashok Doom, 2020-09-15
@Benzin102

https://basicweb.ru/css/css_pr_flex-basis.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question