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 CSS Grid Layout Flexible Sized Grids Control the Auto-placement of Grid Items

gene c
gene c
13,630 Points

How to make the grid direction horizontal instead of vertical when grid-auto-flow: column?

grid-auto-flow: column makes my grid count vertically.

.grid {
  max-width: 1000px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 100px 100px;
  grid-gap: 15px;
  grid-auto-columns: minmax(150px, auto);
  grid-auto-flow: column;
}

it's like:

1 3 5
2 4 6

i want it to be:

1 2 3
4 5 6
Aiden Berzins
Aiden Berzins
23,837 Points

It's helpful to add a snippet of your code so we can help see the issue.

1 Answer

Aiden Berzins
Aiden Berzins
23,837 Points
.grid {
  max-width: 1000px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 100px 100px;
  grid-gap: 15px;
  grid-auto-columns: minmax(150px, auto);
  grid-auto-flow: column; /* change this to row instead of column*/
}
Rich Donnellan
Rich Donnellan
Treehouse Moderator 27,708 Points

The alternative is to let the default behavior take over. Not setting grid-auto-flow is equivalent to setting it to row.