Help! I don't know how to do the grid-templates-areas.

git hub https://github.com/Vali3232/four-card-feature-section-master live site https://vali3232.github.io/four-card-feature-section-master/. I tried chat gpt fot the grid area, youtube, i can't get it to work.
GitHub
GitHub - Vali3232/four-card-feature-section-master
Contribute to Vali3232/four-card-feature-section-master development by creating an account on GitHub.
49 Replies
Jochem
Jochem2w ago
what are you trying to achieve?
Vali3232
Vali3232OP2w ago
I want the grid to be something like this if it makes sense -=- But I don't know how I know that there is the YouTube video on this exact design but i wanted to see how far can i go before i start watching Kevin's video.
ἔρως
ἔρως2w ago
well, you don't need grid areas for this
Rägnar O'ock
Rägnar O'ock2w ago
You don't need grid area, but you can use them if you want
ἔρως
ἔρως2w ago
you can do this way:
.fake-parent {
display: grid;
grid-template-columns: 1fr 1fr 1fr;

& > :first-child,
& > :last-child {
grid-row-start: 1;
grid-row-end: 3;
}
}
.fake-parent {
display: grid;
grid-template-columns: 1fr 1fr 1fr;

& > :first-child,
& > :last-child {
grid-row-start: 1;
grid-row-end: 3;
}
}
if it doesn't work, just add grid-template-rows: auto auto or 1fr 1fr then you just have to do the centering stuff
Rägnar O'ock
Rägnar O'ock2w ago
grid-template-area:
'. Card1 .'
'Card2 Card1 Card3'
'Card2 Card4 Card3'
'. Card4 .';
grid-template-area:
'. Card1 .'
'Card2 Card1 Card3'
'Card2 Card4 Card3'
'. Card4 .';
ἔρως
ἔρως2w ago
that might be closer to what's wanted no, that will have the same effect as this:
grid-template-area:
'Card1 Card2 Card3'
'Card1 Card4 Card3';
grid-template-area:
'Card1 Card2 Card3'
'Card1 Card4 Card3';
wait, it's a bit different, actually
Vali3232
Vali3232OP2w ago
i tried all of them and it doesn't work
Vali3232
Vali3232OP2w ago
it should look like this
No description
Vali3232
Vali3232OP2w ago
that's how it looks now, before it was all in the down right corner so now is better but don't know how to make this shape
No description
Rägnar O'ock
Rägnar O'ock2w ago
grid-template-area defines the areas, but you still need to assign the elements in the grid Something like
.cards:nth-child(1) {
grid-area: Card1;
}
.cards:nth-child(1) {
grid-area: Card1;
}
Rägnar O'ock
Rägnar O'ock2w ago
MDN Web Docs
grid-area - CSS | MDN
The grid-area CSS shorthand property specifies a grid item's size and location within a grid by contributing a line, a span, or nothing (automatic) to its grid placement, thereby specifying the edges of its grid area.
Jochem
Jochem2w ago
they do in style attributes
ἔρως
ἔρως2w ago
show us what you have in a codepen ignore this
Jochem
Jochem2w ago
you can't use the same name for separated areas. The . area is the only exception afaik. So like Ragnar suggested, you HAVE to use this:
grid-template-areas:
". card2 ."
"card1 card2 card4"
"card1 card3 card4"
". card3 .";
grid-template-areas:
". card2 ."
"card1 card2 card4"
"card1 card3 card4"
". card3 .";
ἔρως
ἔρως2w ago
all examples have to work if done correctly
Jochem
Jochem2w ago
you can't call them empty also, I would heavily recommend learning to use the DOM inspector. The way I found this is by examining the element in the DOM inspector, and it showed that the grid-template-areas property value was invalid. From MDN (emphasis mine):
A row is created for every separate string listed, and a column is created for each cell in the string. Multiple cell tokens with the same name within and between rows create a single named grid area that spans the corresponding grid cells. Unless those cells form a rectangle, the declaration is invalid. All the remaining unnamed areas in a grid can be referred using null cell tokens. A null cell token is a sequence of one or more . (U+002E FULL STOP) characters, e.g., ., ..., or ..... etc. A null cell token can be used to create empty spaces in the grid.
Vali3232
Vali3232OP2w ago
.cards{ display: grid; grid-template-areas: ". card2 ." "card1 card2 card4" "card1 card3 card4" ". card3 ."; } i dont know how you made the box for the code
ἔρως
ἔρως2w ago
you have to give the areas to the children each has to have grid-area: card1 or card2 ....
Vali3232
Vali3232OP2w ago
thats how i named my children actually it's perfect now
Jochem
Jochem2w ago
they do, just in a style tag
ἔρως
ἔρως2w ago
oh ew
Jochem
Jochem2w ago
not my personal prefered method, but it works especially cause there's already a class for each card
ἔρως
ἔρως2w ago
yeah, i wouldn't do this way either exactly
Vali3232
Vali3232OP2w ago
chat gpt told me to do it like that:))
Jochem
Jochem2w ago
that's a great reason to not do it that way tbh, LLMs are terrible at CSS
ἔρως
ἔρως2w ago
that's horrible, not gonna lie
Jochem
Jochem2w ago
I might set a variable in the style tag, and then reference that variable in a .cards > article selector If you're still learning, avoid ChatGPT like the plague, especially for generating code
ἔρως
ἔρως2w ago
i only do that on a style attribute or tag if i have to change it with js
Vali3232
Vali3232OP2w ago
how whould it be done in css? setting the grid areas
Jochem
Jochem2w ago
you're just going to poison your brain with hallucinations, and when the bubble bursts those free tiers are going to evaporate like water in the desert just set the grid-area in the .card1 selectors you already have!
ἔρως
ἔρως2w ago
just add each grid-area to each class in the css file
Jochem
Jochem2w ago
.card1{
border-top: 4px solid var(--primary-cyan);
grid-area: card1;
}
.card1{
border-top: 4px solid var(--primary-cyan);
grid-area: card1;
}
Vali3232
Vali3232OP2w ago
i'm trying to learn html and css for 3 monts and usually i write all the code myself, when i get stuck i ask the ai
ἔρως
ἔρως2w ago
no don't do that please
Jochem
Jochem2w ago
just, please, learn to code... forget the vibe coding until you know enough to tell if ChatGPT is lying or not, and if you get stuck, ask here or on a thousand other servers
ἔρως
ἔρως2w ago
you will learn it all wrong, or not at all you will just use the ai to learn it for you instead of you knowing what to do knowing how to "unstuck" yourself is a very important skill you MUST learn ai is just not how you do it specially since it ACTIVELY LIES TO YOU but not only it lies, it tries to convince you that you're wrong or just agrees you're right and writes the most halucinated halucination to ever been halucinated
Vali3232
Vali3232OP2w ago
i had a couple of courses on udemy to begin with, after them and exercizing a bit i hit youtube tutorials and more exercizing
ἔρως
ἔρως2w ago
how about less tutorials?
Vali3232
Vali3232OP2w ago
i'm trying to do this with manny forntend mentor projects
ἔρως
ἔρως2w ago
good, as you should to test yourself accurately
Vali3232
Vali3232OP2w ago
That is the goal i don't know if i should try doing the java script courses on udemy, or i should sit more on html/css for now
ἔρως
ἔρως2w ago
focus on css and html first you're not ready yet
Vali3232
Vali3232OP2w ago
okay
ἔρως
ἔρως2w ago
give it a month or 2, and you will be better prepared
Vali3232
Vali3232OP2w ago
Trying this, but i have a full time job so depends how much time do i allocate every evening for learning:)
ἔρως
ἔρως2w ago
also, make use of the #showcase channel to show your completed projects and ask for feedback
Vali3232
Vali3232OP2w ago
Okay, thank you, i'm gonna try and finish this now.
ἔρως
ἔρως2w ago
you're welcome

Did you find this page helpful?