FAQ: Advanced CSS Grid - Grid Auto Flow

This community-built FAQ covers the “Grid Auto Flow” exercise from the lesson “Advanced CSS Grid”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn CSS

FAQs on the exercise Grid Auto Flow

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

1 Like

Why this property is used because I have not noticed any changes in the website on the right side?
I also used all of It’s values mentioned.

4 Likes

grid-auto-flow …

using column will push the 2 added Recipes into another column.
using row the 2 added Recipes appear at the bottom of the page.

4 Likes

In this exercise when we use the property grid-auto-flow: column; this property reorganize container to fit in the remain space.
The first and second column has a margin on the left and right side that you can see only using inspection.
But the third one that was fit on the right side don’t has this margin.
How to solve this issue?

To solve this I had to make some changes:

ORIGINAL

main {
display: grid;
grid-template-columns: 250px 250px;

CHANGED

main {
display: grid;
grid-template-columns: repeat(auto, 250px);

2

5 Likes

When I use grid-auto-flow: column; , not just the newly added extra elements filled the columns from top to bottom, but all the contents did.
So it works on not just implicit elements?

2 Likes

This technique is great to be aware of. Thanks!

3 Likes

I don’t notice any difference in the example website when I assign a value to Grid-auto-flow. Is it me or is it the exercise?

1 Like

In the right-most window (browser view) of the exercise, there is a pair of diagonal arrows. You can click them to switch between full and condensed views of the browser window.

As @propokeruk mentioned, if you use grid-auto-flow: row; which is the default, you will see the two new duplicate recipes (sweet churros and berry parfait) appear at the bottom of the rows.

If you use grid-auto-flow: column; the new recipes will be added in a new column.

2 Likes

Thank-you for replying, the screenshots of how it should look are very helpful! I did try to expand the window as you suggested during the lesson and there was no change. I reset my code, did it again, expanded all windows - I tried it all, i think, and it was still coming up squished together at the bottom of the 2nd column. Now I know what to expect though, so thank-you for taking the time :slight_smile:

2 Likes

This is a really useful information .Thanks from my side. :smile:

1 Like

Not sure if this is the right place to ask this but…

How do are we positioning the child elements like the h2 and p so that they always appear underneath each other?

I understand that the div is the container but how do we position text within that? (maybe I’ve missed/forgotten a lesson

cheers

Not entirely sure I understand the question. Perhaps you will elaborate if I am misunderstanding the issue.

In index.html, we have the <main> tag. Within the <main> tag, we have a series of child divs. Each of these divs has the class “recipe” and also another class which is unique for each div e.g. <div class="recipe a"> and <div class="recipe b"> etc.

In style.css, we have set some rules for the <main> tag which specify how we want the children of the main tag to be displayed in a grid.

Additionally in style.css, we also have rules for img, h2, .time, .recipe, .mins, .description which help us further customize how the elements within each div are to be positioned.

Thank you mtrtmk!

I have been creating separate divs for h3 and p elements to get them into the position i wanted, rather than using the CSS styling with class.

After your help and a few more youtube videos I have managed to place them into the desire position. (I will keep working on it)

2 Likes

In the exercise, I didn’t include grid-auto-column in the code and the grid-template (grid-template-columns: 250px 250px;) is set so that the grid only has two columns. So why did grid-auto-flow: column added a new column when the template says there should only be two?

From the documentation for grid-auto-flow:

row

Items are placed by filling each row in turn, adding new rows as necessary. If neither row nor column is provided, row is assumed.

column

Items are placed by filling each column in turn, adding new columns as necessary.

1 Like

Oh… I get it now. So basically, the template of two 250px columns are what is called explicit while the ones added by the auto-flow is implicit. That’s why they don’t actually contradict each other.

“grid-template-column” sets explicit columns
while
“grid-auto-flow: column” adds implicit columns

I see, thanks!

1 Like

I have a problem but idk why, when i have my website screen in small window it looks fine, like this:


but when i go in full screen it looks like so:

In your top screenshot, you are missing a rule within the the main selector of your style.css file. Perhaps, you need to reset the exercise for the rule to reappear (it appears for me just fine, perhaps it was accidentally deleted in your file.).
Alternatively, you can add the rule yourself.
The relevant rule to be added within the main selector is justify-content: center;
That should fix the problem you are seeing. If you omit/delete this rule, then the justify-content property takes on the default value of “normal” which can result in behaviour similar to your screenshot.