FAQ: CSS Grid Essentials - Repeat

This community-built FAQ covers the “Repeat” exercise from the lesson “CSS Grid Essentials”.

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

Learn CSS

FAQs on the exercise Repeat

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!

Can someone explain this exercise to me? I don’t get it…
repeat(3, 1fr) / 3fr 50% 1fr;
How does this end up being 7 rows and 1 column?

1 Like

There is 3 rows and 3 columns.

1 Like

it’s probably creating 7 rows, because you are using codecademy HTML template with 7 divs. Check your HTML code, 7 items :slight_smile:

but can we combine “repeat” with Grid Template to optimize the code?
or it’s only for rows/columns:

grid-template-rows: repeat(4, 50% 150px 150px);
grid-template-columns: repeat(44, 1fr);

thanks

PS: grid-template: repeat(12, 1fr) / repeat(6, 1fr);

So like, I wasn’t able to complete the exercise on my own because I thought the repeat function was only for rows/columns. But when I got the solution, apparently it works for Grid Template to optimize the code.

There are three rows. The first row has 3 items. The second row has 3 items. The third row has 1 item.

Each item is represented by a <div> in the HTML code.

2 Likes

It is simply a shortcut.

grid-template-columns: repeat(2, 20px 50px)

“This code will create four columns where the first and third columns will be 20 pixels wide and the second and fourth will be 50 pixels wide.” This from the curriculum.

It seems intuitive that this would produce 4 columns of 20, 20, 50, 50 but the answer says that we don’t move sequentially from left to right when we use the repeat function. We treat the 20px and 50px like a pair and repeat the pair?

3 Likes

What repeats is the space separated sequence following the count value. There is only one comma in that expression. Repeat 20px 50px means the distribution will be 20px 50px 20px 50px

6 Likes