Design for Developers

Grid Naming Example

Design for Developers

Check out a free preview of the full Design for Developers course

The "Grid Naming Example" Lesson is part of the full, Design for Developers course featured in this preview video. Here's what you'd learn in this lesson:

Sarah highlights additional CodePen demonstrations that illustrate the ease with which grid can create complex and responsive layouts with little code, and using naming to create your own layout schema.


Transcript from the "Grid Naming Example" Lesson

>> Sarah Drasner: Here's where we get into some really cool stuff. You can name areas. So for each one of these things, I'm gonna say okay, item a is the header, item b is the main, item c is the sidebar, item d is the footer. So now if I uncomment this stuff, I have that good column gap, the grid row gap and these template areas.

We've got a header, some content, a side bar and footer. Let's go back and look at the code a little bit more. Actually, I'm gonna change the view to the side. So you can see a little bit more clearly in this view. What we did was we said that we wanted the header to go all the way across.

So we're basically saying that we want, instead of saying repeat five pieces of one f r, we're using the name of this to create that unit. So we're going five across. Then we're saying main, main, main, take a break [LAUGH] and don't put something in here, sidebar. And then we go, footer, footer, footer, footer, footer.

And the grid template rows are going to say, I want the header to be 40 pixels to fill up the rest with auto and then be 80 pixels. So I could actually make this header 80 pixels if I wanted to, and then it would drop down. That's a whole layout, right?

You could start using that content and this is really that whole header, even though I said header, header, header, header I didn't have to put for dibs in there. Before, remember we had to span all the way across like that. We can really just start making our nav inside here, and you could even use flexbox inside of grid, right?

So let's say I wanted to make a nav and I wanted to line up all of the items really quick and you're really flex. You're used to flex-box and you know how to work with it really well. You could put a nav inside there and use flex-box for the items in the nav, totally fine.

And it's just all organized based on those areas. I don't have to call them header main side bar. That's a little more eligible for whoever comes along and maintains my code later, right? But I could also call it Donkey pants or something like that. And that would also work.

So definitely name them donkey pants and just confuse all of your coworkers [LAUGH]. All right this is our friend, we know him already. This just goes boop boop boop and kind of makes all of these kinda go across. They're just a bunch of items and then that item a has a background of teal yeah?

So we've got our usual suspect of display grid. We go all the way across, all the way down. You don't have to go all the way across all the way down too like, right if I wanted to do a height of 50 my grade gets squishy. So you don't have to use it for the entire layout if you don't want to.

That's totally fine. Okay, so most of these dibs are gray. But one, is teal. So what if we want this one to layout somewhere else on the page because when we were making all of those grids earlier, we weren't just sticking things in boxes everywhere. So maybe we want it to start somewhere else.

Well, we have this kinda grid column start, grid column end, grid row start, grid row end. So there's a few different options here and I combined. I'm showing you two different options at the time. So grid column start, is going to go over here. It's not starting from one, it's not base zero.

That's confusing to me. [LAUGH] It's one and two so it starts here. And then it spans across three. And then grid row start is 3. And then I'm saying grid row end 6. It could go 5, wait that is 5, sorry I messed that up. So 3 and then it ends there.

But if I say span 2 then it's saying how many it spans. That's kind of intuitive, right? Like one of them is defined by the line and the other one is defined by how much it spans. But this is a long way to write this. That's a very long way of writing all of these things.

So we can also write it by grid area. And the grid area goes the start of the row, the start of the column, the end of the row, the end of the column. So it's always .again and again in browsers we do x and then y and then x and then y.

When I look at this I'm like, I want to start with y here, but actually if I think about the way that, when we go grab things in the DOM, those boxes are always x, y, x, y, x, y. So it follows that same kinda standard. So we're basically saying, start at 2, start at 3, span 3, span 2.

So row, column, row, column, pretty cool? Not that bad. It's like pretty easy to work with, yeah? You can get a lot done with grid pretty quickly. Again, I am not a grid expert this is like me playing around with it for the past few weeks or something like I've done a few great light outs before this.

But I am not, I don't know the spec like the back of my hand like those other people that I mention before, but I can go pretty far with it without a lot. Without being a great expert, which is the cool part. I don't have to be the worlds expert in it, in order to make these layouts.

So here we are using this thing called Minimax. Minimax is my favorite thing you guys, it's so cool. So with Minimax we're basically saying what we want things to start and end with, without using media queries. Like check this out, item as wide as the content but at most 300 pixels.

Item with flexible width but with a minimum of 200 pixels. An inflexible item of 150 across, so look at how it stopped at 200. This one it won't get so small that the content row, if I took the text out it would kind of smoosh even further. But as I go out, it will stop at 300 pixels.

And this isn't my example, the rest of them are my examples. But this one is off of the Mozilla Docs, which are the MDN Docs are fantastic. I just couldn't find a way of improving on it, so I was like whatever, I'll just show this. [LAUGH] I kind of wish that we had Minmax for everything.

Like, what if you could define H1 sizes with just min max? Like, you wouldn't have to dump everything in Media queries. Wouldn't that be cool? Anyway, [LAUGH] but I think that this is a really fascinating part of it because we just created a really responsive layout without having to put things in different areas and stuff, super great.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now