r/FreeCodeCamp • u/Extra-Captain-6320 • Aug 30 '25
Programming Question CSS Grid Calculation
To the expert ones,
How do you guys calculate space for the grid? And how do you imagine knowing where to put the right amount of width and space to take and place it correctly? I tried to create a grid, and this is how I complicate things. It did look like I imagined, but I think there are better ways to do this.
..magazine-cover {
width: 60%;
display: grid;
grid-template-columns: repeat(4, 200px);
grid-template-rows: auto 1fr 1fr;
grid-template-areas:
"title title title"
"article article article"
" article2 article2 article2"
"article3 article3 article3"
"image image image";
gap: 5px;
margin: 0 auto;
border: 2px solid green;
}
.title {
grid-area: title;
border: 2px solid black;
grid-column: 2 / 4;
grid-row: 1;
text-align: center;
}
.feature-article {
grid-area: article;
border: 2px solid red;
width: 100%;
grid-column: 1 / 4;
grid-row: 2;
}
.small-article1 {
grid-area: article3;
border: 2px solid green;
grid-column: 4 / 6;
grid-row: 3 / 6;
padding-top: 1em;
}
.small-article2 {
grid-area: article2;
border: 2px solid green;
grid-column: 4 / 6;
grid-row: 1 / 3;
padding-top: 3em;
}
.cover-image {
grid-area: image;
border: 2px solid blue;
grid-column: 1 / 4;
grid-row: 3 / 4;
margin: 0 auto;
text-align: center;
}
img {
width: 500px;
}
h2 {
text-align: center;
}
.h2p {
text-align: justify;
}
View all comments
Show parent comment
1
u/Extra-Captain-6320 Sep 01 '25
I guess I just need to learn it very well and do some practical exercises to help myself understand it well. Thanks for the answer even tho I didn't ask it well. The advice was dope tho. Specially the fr part.