Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS

Mixing columns and rows in flexbox

Hi...I'm trying to mix columns and rows in flexbox. Is this possible without being nested?

Image of what I'm tryin to accomplish is here https://dl.dropboxusercontent.com/u/72594893/Tim%20Working%20Copy/test/flex_question.png

i think maybe a bit much to explain on this form well for me anyway but you can check this web-site it has every think about the flex-box layout and good tip and tricks. https://css-tricks.com/snippets/css/a-guide-to-flexbox/

2 Answers

Steven Parker
Steven Parker
242,191 Points

I don't think you can do that without nesting. But — what's wrong with nesting? Flexbox nests so easily!

:point_right: This does exactly what you want:

code.html
<div class="flexcol">
  <div class="item"></div>
  <div class="flexrow">
    <div class="item"></div>
    <div class="item"></div>
    <div class="item flexcol">
      <div class="item"></div>
      <div class="item"></div>
    </div>
  </div>
  <div class="item"></div>
</div>
styles.css
div {
  outline: 2px solid white;  /* <-- just for demonstration */
  min-height: 50px;          /* <-- just for demonstration */
}
.flexrow {
  display: flex;
  flex-direction: row;
}
.flexcol {
  display: flex;
  flex-direction: column;
}
.item {
  flex: 1;
  background-color: blue;    /* <-- just for demonstration */
}

Thanks. I took a nested approach as well.