FAQ: CSS Grid Essentials - Fraction


#1

This community-built FAQ covers the “Fraction” 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 Fraction

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!


#2

grid-template-columns: 3fr 50% 1fr;
and
grid-template-columns: 3fr 4fr 1fr;

Don’t these lines do the same?


#3

Confused by fr exercise? Does anyone have a simple explanation of how they understood this exercise?


#4

Just going through lessons myself, so corrections are welcome;

Using fr is a way to use fractions to divide the space. The bottom of the fraction is determined by how many units of fr you use overall.

Say you have 1 column:

grid-template-columns: 1fr;

That means that column is 1/1 of the width of the grid.
But now you add a second column:

grid-template-columns: 1fr 1fr;

Now each column is 1/2 of the width of the grid. Each column is 1fr and there are a total of 2fr, so 1/2.
And this extrapolates out:

grid-template-columns: 1fr 2fr 1fr 5fr;

Now there are four columns, and a total of 10fr. So, in order, each column width is 1/10, 2/10, 1/10, 5/10.

Also, the fractions only account for undefined width. If any of your columns have a defined width, it is ignored from the fraction.

grid-template-columns: 1fr 2fr 1fr 5fr 50%;

We’re still at 10fr total, but the new column is set to 50% of the width, so now the fraction columns are fighting over half of the space they had before.

Say that:

width: 1000px;

Before we introduced the 50% column, the column sizes would have been 100px (1/10), 200px (2/10), 100px (1/10), 500px (5/10).

But with the 50% column introduced and stealing 500px of the total 1000px, the fraction column sizes have changed: 50px (1/10), 100px (2/10), 50px (1/10), 250px (5/10).

Hope that all makes sense and I’m not spouting anything super wrong!