2

I have a nav bar and a main area that is divided to 2 equal halves, left and right.

When the left half contains a wide element that overflows its width, the 50/50 division of main breaks, causing left to take more than 50%.

Why is this happening?

How could I avoid that?

.container {
  display: flex;
  height: 100px;
  background-color: #ccc;
  width: 300px;
}
nav {
  flex-shrink: 0;
  background-color: #aaa;
}
main {
  display: flex;
  flex: 1;
}
.left {
  flex: 1 0 50%;
  background-color: #bbb;
  overflow: auto;
}
.wide {
  width: 300px;
}
.right {
  flex: 1 0 50%;
}
<div class="container">
  <nav>Navigation</nav>
  <main>
    <div class="left">
      <div class="wide">Left</div>
    </div>
    <div class="right">Right</div>
  </main>
</div>
Misha Moroshko
  • 166,356
  • 226
  • 505
  • 746
  • 3
    Add `min-width: 0` to `main`. (An initial setting on flex items is `min-width: auto`. This means that, by default, a flex item cannot be smaller than its content size. You need to override the default.) – Michael Benjamin May 26 '17 at 01:17

0 Answers0