DEV Community

CSS Grid Areas are amazing

Ken Bellows on December 31, 2018

When I first learned about CSS Grid Layout and the new powers it gave us as CSS developers, I was immediately excited. I was thrilled at the prospe...
Collapse
 
omhax profile image
Om Hax

Hi, this is great tutorial. Can you make navbar like dev.to?

Collapse
 
kenbellows profile image
Ken Bellows • Edited

Sure, you can add an element at the top like <nav id="navbar">, then add a navbar grid area and assign the element to that area. But as far as positioning content within the navbar, I actually think Flexbox might be the better choice for layout system, since it's a one-dimensional layout that needs to be flexible

Collapse
 
omhax profile image
Om Hax

You can show me tutorial? The dev.to is awesome navbar.

Collapse
 
stevetwitte profile image
Stephen Taylor Witte

Great article about an excellent addition to CSS! I would add that this doesn't replace the functionality provided by flexbox as that is still a better solution in some cases. A dynamic length list of cards is one example that comes to mind.

Collapse
 
kenbellows profile image
Ken Bellows • Edited

Oh, definitely, Flexbox has plenty of advantages on many circumstances. I didn't mean for this article to be a proper intro to Grid, so I didn't bother with the usual "when to use it" discussion.

Actually though, regarding your example with cards, depending on what the cards look like I might still use Grid in order to keep the elements of the cards inline with each other, keep them the same height and all that. I'm actually currently working on a post about just that topic right now, and how display: contents and the upcoming subgrid addition factor into that kind of a layout.

Collapse
 
stevetwitte profile image
Stephen Taylor Witte

Can't wait!

Thread Thread
 
kenbellows profile image
Ken Bellows

ICYMI, I published it yesterday! dev.to/kenbellows/why-we-need-css-...

Collapse
 
rhymes profile image
rhymes

OMG Ken, this CSS grid thing is awesome and so intuitive! Thanks for explaining it so well!

I also read this post by Rachel Andrew: You do not need a CSS Grid based Grid System.

Not writing rows and columns wrappers in the markup is liberating (especially because I might be able to stop littering the markup with those helpers only needed by the framework). It definitely helps accessibility too, as you mentioned.

I spent most of 2018 using Bulma (based on Flexbox) but this is much better.

It is finally time to start leaving CSS frameworks behind, or just use them for the components and not for layout :D

Vanilla CSS, vanilla JS, JAMstack websites... the web is getting simpler again ;-)

Collapse
 
kenbellows profile image
Ken Bellows

Yeah, definitely! I always hated digging through the layers of bootstrap containers to find the actual content; I'm thrilled to be able to write clean markup finally!

Another thing to look into with laying out components in a grid while maintaining semantics is display: contents, which I hope to write another article about soon.

Collapse
 
hashimwarren profile image
Hashim Warren

I haven't tried named areas yet. Thanks for the enthusiasm. I feel hyped to try it

Collapse
 
kenbellows profile image
Ken Bellows

Any time! Post a link if you do something fun with it