CSS CSS Flexbox Layout Flexbox Properties Wrapping Items and Distributing Space

Colin Bondi
Colin Bondi
4,808 Points

I don't understand what I'm doing wrong here, I though setting flex-direction: column would accomplish this?

Not sure what I'm doing wrong

style.css
/* Complete the challenge by writing CSS below */

.row {
  display: flex;
  flex-direction: column;
}
index.html
<!DOCTYPE html>
<html>
<head>
  <title>Flexbox Layout</title>
  <link href='https://fonts.googleapis.com/css?family=Varela+Round' rel='stylesheet' type='text/css'>
  <link rel="stylesheet" href="page.css">
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <div class="row">
    <div class="item">Item 1</div>
    <div class="item">Item 2</div>
    <div class="item">Item 3</div>
    <div class="item">Item 4</div>
    <div class="item">Item 5</div>
    <div class="item">Item 6</div>
  </div>
</body>
</html>

2 Answers

andren
andren
28,418 Points

A flex contained will always try to fit it's items within a single line, changing the flex-direction only changes the direction of said line. It does not change the fact that it still does not wrap to other lines when it runs out of space.

The property that controls that behaviour is flex-wrap. By setting flex-wrap to wrap flex will wrap to another line If it runs out of space.

Colin Bondi
Colin Bondi
4,808 Points

Thanks, now it makes sense...