So far, you've learned about grid-container properties, but what about grid cells and grid items? Like Flexbox layouts, containers and items have their own unique properties to enhance and customize the layout of the grid. Click through the tabs below to learn more about what properties can be applied to grid items.
As you've learned, a grid container houses grid items. By default, a grid will place one grid item per grid row, unless we explicitly tell it otherwise. When it comes to sizing and placing individual grid items, we use the following properties.
Column
Row
grid-column-start
row-column-start
grid-column-end
row-column-end
Each property will accept one of the three values.
auto: This sets the grid item to default to any size explicitly outlined by the parent grid container.
grid line number: This sets the grid item to start on a designated line number.
span: This tells the grid item how many columns or rows the item should occupy.
Let's look at a familiar example...
1
2
3
4
5
6
This is a grid layout from the previous page. We can see that grid item number 3 spans two columns and that grid item number 5 spans two rows.
Let’s look at a few more examples. Look at the images below and see if you can determine what properties and values were used. Click on the images to see the code snippets for each property.
Another way to lay out your grid items is using the grid-template-areas and the grid-area properties. The grid-template-areas property is a grid-container property that uses the grid-item property grid-area to structurally visualize our desired layout.
Click through the slideshow below to see the grid-template-areas property in action and how to use the grid-area property to accomplish it.
Let's use the following layout as an example. This is a basic web page layout that contains a header, footer, navigation, and a main content area.
When establishing this layout, you first need to know how much space you would like each element to occupy. This will help you set up your grid structure. For this example, a 6-column grid is being used.
If you break down this layout, you can see the following:
The header occupies all 6 columns.
The navigation occupies 2 columns.
The main content occupies 4 columns.
The footer occupies 4 columns with 1 empty column on each side.
To make this grid layout, you need to first establish the grid container, then create the 4 grid items in HTML, and finally assign a grid-area name to each grid item, using the grid-area property.
When assigning a grid-area item name value, you should keep the naming conventions as semantic (meaningful) as possible. This will not only help you stay organized but will help others you may be collaborating with to understand your code. In this example, an abbreviation for each section is given.
Next, within the grid-container property, you use grid-template-columns to establish your 6-column grid. (Remember, the number of values = the number of columns.)
Once your 6 columns are set, you can then use the grid-template-areas attribute to place the page elements, using the grid-area name values that were just assigned.
You know that the header will occupy all 6 columns, so you place that value 6 times, once for each column.
Beneath the header, you have the navigation in two columns and the main content in 4 columns.
Finally, you have the footer, which spans 4 columns and has a blank column on either side. Blank columns can be represented with a ''.'' symbol. (See below.)
<style>
section.grid-container {
/*...previous styling...*/
grid-template-areas:
'hd hd hd hd hd hd'
'nv nv mn mn mn mn'
'. ft ft ft ft .'
;
}
</style>
As you can see, the grid-template-areas values look very similar to the desired page layout!
<style>
section.grid-container {
display: grid;
gap: 10px;
grid-template-columns: repeat(6, 1fr);
grid-template-areas:
'hd hd hd hd hd hd'
'nv nv mn mn mn mn'
'. ft ft ft ft .'
;
}
</style>
Slide:
You Try!
Using your own text editor or the coding space below, test your skills on the properties we just learned! Practice different layouts and configurations and see what is and isn't possible. Try combining the grid-template-areas property, grid-area property, and the grid-row-start/stop properties and see what happens! When you think you've got the hang of it, move on to the next page in this lesson.
Text
Guided Notes
Tutor
Video
How To
Meet your new study partner! With our powerful Student Tools, your online learning experience just got more accessible,
personalized, and thought-provoking than ever before!
Do you feel like you learn better when you watch videos? You’re not alone!
Research shows instructional videos can make learners more engaged and active in online classes,
when compared to text-only lessons.
Student Tools lets you turn some lesson pages into videos instantly! Just click the Student Tools tab and select Video.
Remember, video instruction is not available on every lesson page.
Go back to the lesson page any time by closing the Student Tools window.
Sometimes when you learn, it can feel like you’re just not getting it. Maybe you don’t really know what all the words on
the page mean, or you have to read a paragraph two or three times to understand what it’s about.
If this happens to you, just click the Student Tools tab and choose “Text.” This will automatically
simplify the instruction, making it easier to understand and remember.
Go back to the lesson page any time by closing the Student Tools window.
The science is in, and taking notes is one of the best ways to reinforce your learning.
Notes work even better when you write them by hand, since you’re more likely to put complex new ideas
in your own words and remember them longer.
You can quickly and easily access guided notes, as well as key lesson vocabulary,
by clicking Student Tools > Notes. Choose a PDF or Word Doc,
and fill them out online -- or even better-- print them out and take notes by hand!
Go back to the lesson page any time by closing the Student Tools window.
Imagine a teacher you can contact anytime, who is happy to answer all your questions and
knows pretty much everything in the world about the subject you need help with.
Say, “Hello!” to your Tutor! Click on Student Tools > Tutor, and ask any question about your class.
Your Tutor is super smart! You can ask the Tutor to explain things more clearly, make connections
between ideas, or even give you custom quizzes and feedback. You can click the links under References to learn more.
Go back to the lesson page any time by closing the Student Tools window.
Student Tools lets you create your own Flashcard decks to help you study. To get started, click Student Tools >
Flashcards. Press Add New Set and give it a title.
Now, decide what will be on the front and back of your first card. It can be a term and definition, a challenging question,
or even a funny phrase that helps you remember something. Click Add Card to Set to make a new Flashcard.
You can delete sets or cards by clicking the trash can icon. When you’re done, click Save Cards to Set.
Now you can Review your deck. Read the front of the card, and think of the answer. Even better, say your answer out loud! Then, click the card to flip it over.
Depending on how you did, you can either keep that card in the deck to study again by clicking Next or Previous, or if you got it right, click remove.
Remember to review your flashcards often, space out study sessions, and keep practicing until you know them all!
Go back to the lesson page any time by closing the Student Tools window.