Chrisstar Chrisstar - 1 month ago 4
CSS Question

Wrap error with flexbox

I have two div, the first one is a top bar, the second one should cover the rest of the page. These two are wrapped by a wrapper div. But if the second div's content get's higher than the remaining space, the div should scroll (not the page). But instead it stops breaking to a new line it alignes itself next to the first div. I don't understand what mistake I do here, maybe you can spot my problem:

#wrapper, body, html{
height: 100vh;
}
#topbar {
width: 100%;
height: 2em;
border-bottom: $color 0.15em solid;
display: flex;
padding-left: 1em;
div {
line-height: 2em;
padding: 0 0.5em;
cursor: default;
transition: background 0.3s;
&:hover {
background: $accent;
}
}
}
#wrapper {
display: flex;
flex-wrap: wrap;
flex-direction: column;
}
#main {
display: flex;
flex-grow: 1;
overflow: auto;
.main-column {
border-left: $color 0.15em solid;
flex-grow: 1;
}
}


http://codepen.io/Chrisstar/pen/LRrOKP

Answer

you may use flex-flow instead flex-direction and apply it to .main too.:

body {
  background: #292929;
  font-family: 'Open Sans', Helvetica, Arial, sans-serif;
  height: 100%;
  font-size: 16px;
  color: white;
  margin: 0;
}

#wrapper, body, html {
  height: 100vh;
}

#topbar {
  width: 100%;
  height: 2em;
  border-bottom: #7CB342 0.15em solid;
  display: -webkit-box;
  display: -webkit-flex;
  display: -ms-flexbox;
  display: flex;
  padding-left: 1em;
}
#topbar div {
  line-height: 2em;
  padding: 0 0.5em;
  cursor: default;
  -webkit-transition: background 0.3s;
  transition: background 0.3s;
}
#topbar div:hover {
  background: #5F8339;
}

#wrapper {
  display: -webkit-box;
  display: -webkit-flex;
  display: -ms-flexbox;
  display: flex;
  -webkit-flex-wrap: wrap;
      -ms-flex-wrap: wrap;
          flex-wrap: wrap;
  -webkit-flex-flow: column;
      -ms-flex-flow: column;
          flex-flow: column;
  /* update */
}

#main {
  display: -webkit-box;
  display: -webkit-flex;
  display: -ms-flexbox;
  display: flex;
  -webkit-flex-flow: column;
      -ms-flex-flow: column;
          flex-flow: column;
  /* update */
  -webkit-box-flex: 1;
  -webkit-flex-grow: 1;
      -ms-flex-positive: 1;
          flex-grow: 1;
  overflow: auto;
}
#main .main-column {
  border-left: #7CB342 0.15em solid;
  -webkit-box-flex: 1;  
  -webkit-flex-grow: 1;
      -ms-flex-positive: 1;
          flex-grow: 1;
}

*, *::before, *::after {
  box-sizing: border-box;
  padding: 0;
  margin: 0;
}
<div id="wrapper">
  <div id="topbar">
    <div>One</div>
    <div>Two</div>
  </div>
  <div id="main">
    <div class="main-column">
      e<br /> e
      <br /> e
      <br /> e
      <br /> e
      <br /> e
      <br /> e
      <br /> e
      <br /> e
      <br /> e
      <br /> e
      <br /> e
      <br /> e
      <br /> e
      <br /> e
      <br /> e
      <br /> e
      <br /> e
      <br /> e
      <br /> e
      <br /> e
      <br /> e
      <br /> e
      <br /> e
      <br /> e
      <br /> e
      <br /> e
      <br /> e
      <br /> e
      <br />
    </div>
    <div class="main-column">
      w
    </div>
    <div class="main-column">
      w
    </div>
  </div>
</div>

http://codepen.io/gc-nomade/pen/jrXpzL

Comments