Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Once you understand the basics behind grid syntax, you can start to create more complex layouts. In this exercise, we are going to dig a little deeper into working with grids by exploring how to nest grid layouts inside one another. I am just going to sort of go over to the page structure with you and preview it in the browser, because you can see that part of the layout is already done, so here I have the same page opened up within the browser, and I can see that I do have a two-column layout happening here. Here is my sidebar on this side and my content is on the left. One of the things I noticed when I was looking at some of the earlier finished files in the sample site is that the sidebar is over on the left-hand side.
So I want the sidebar on the left-hand side; however, the source order isn't allowing that. Because this main content comes before the sidebar in the source order, all of the different column layouts use a float-left. So basically what's happening here is it's forcing me to show this up on the left side of the screen. Well, I can change that too. If I go back into the code, and you can see what's going on here, we have a div with a class of row that surrounds the whole page. Again, that's sort of making sure that all of our content is centered, and it's all part of one big row.
I have a header, and that doesn't have any rows inside of it, but directly after that, I have another sort of generic div tag that's serving as a row, and this is basically controlling this part of the page right up here that has a logo and a tagline, that sort of thing. Now below that, we have another row, and this is giving us our two-column layout, so we have an article here, and you can see it has a "main nine columns" class to it. Now below that article we have an aside, it's spanning three columns, so again, those two are adding up to 12, and then after that there's the closing of that div tag's role and then there is a footer, and of course, the footer doesn't have any rows inside of it at all.
Well, the first thing I want to address is the fact that I would really like the sidebar to show up on the left-hand side and have the main article show up on the right-hand side. So what I am going to do is I am going to apply some classes that are built into the framework that allow you sort of tweak your layouts, so in addition to the main nine columns class that's applied to the main article here, I could also give it a class of right, and that's going to do a float- right instead of a float-left. That also means that I could go back down to the sidebar or the side down here and give it a float of left. Now it already has a left-float applied to it, so really the only reason for me to do that is so that I am sort of leaving myself a little trail that, hey, you wanted this to show up on the left, so if I Save that, go to the browser, and Refresh that, you can see that now the sidebar is on the left-hand side, the main content is on the right-hand side, and that is exactly what I wanted there.
Now one of the things that's going on my form right now that I want to change is these text inputs are really wide. They are taking up the entire length of the main article, and that's based on design. All your form's inputs are designed to go to 100% of their parent's width. So I'd really like to stack these sort of beside each other, and to do that, I could simply use the grid layout to create another row if you will, a nested grid inside my main grid and then control them within that space. So let's see how we would do that. So I am going to scroll up to my form, and once I am in my form--now remember what I want to do is I want the Name and the Email to appear beside the Personal Site and Subject so that'll maybe use the space a little better, but it creates a sort of nested two-column look inside of my form.
So what I am going to do is I am going to highlight all four of those guys. So that's going to be the Name, Email, Personal Site, and Subject, and I make sure that I'm getting both the labels for those and the input types. I am going to wrap them in a div tag with a class of row. So just like that I am establishing a new row. Remember, this is a new row within a column. Every single row has 12 columns to it. So it doesn't matter whether it spans the entire page or whether it's inside of section, I still have 12 columns that I can use. And so now what I am going to do is I am going to go ahead and wrap each one of the individual inputs and labels, so the label for Name, go ahead and hit that down on its own line and its input, I am going to wrap those in a div tag, and I am going to give them a class of six columns.
And I am going to do that for each of these. So I am just going to grab the label and the input and go ahead and give it a div and give it a class of six columns. I didn't necessarily need to use four individual div tags, I could have used two, but in this case, I get to control the order of how these appear a little bit better, so six columns. And then finally, this last one here, I am going to wrap these guys in a div tag as well and do a class of six columns.
Now let me apply my source formatting so that this is maybe a little less confusing for you guys. In this form you are going to notice that directly inside of it, we have a new row established, and that row is covering up all of these inputs. Each input is in its own div tag. Each one of those is controlling exactly how wide within that row these inputs should be at six columns that are going to stack them right beside each other. So if I Save this, go back to my page, and Refresh this, now you can see my form has a two-column layout nested inside the overall page layout.
So again, that row that we established right here has a full 12 columns inside of it. So anything inside that I can space out the same way, hey, you need to be four columns, you need to be six columns. As long as they add up to 12, you are okay. Now remember, we also did the block grid for our radio buttons early on. They really look the same, and I certainly could have had the exact same effect by creating another row and using that. So it just gives you the framework based on which framework you are using, it's going to give you multiple ways to achieve the same layout. Now the last thing I want to do is I want to control my footer.
Right now you can barely even see this footer. It's got some links down on it, it's got a search bar, but you can't see them because they are not fitting inside of that. So what I am going to do is I am going to go down to my footer, and one of the things I want to point out when I am working with the footer is that you don't really necessarily always have to wrap something in a div tag. Sometimes the parent container can be the row. So for the footer, all I have to do here is give it a class of row, and that establishes a new row, and now any of the things inside of there, I can go ahead and use these column classes to determine exactly how much space within the footer that takes up.
So the first thing I am going to do is I am going to take this initial paragraph right here, and I am going to give that paragraph a class of two columns, then for navigation, I am going to go ahead and give that nav element a class of seven columns, so now I am up to nine, and that means the form that's in here, I can alter its class and make an addition to search, I can go ahead and make that three columns as well. Now it's going to add up to nine. So if I Save this, go back into my browser, and Refresh the page, when I get down to the footer, you can see the paragraph is taking up two columns, my nav down here is taking up seven columns, and then the search is taking up an additional three columns, and that allows me to lay my footer out without really having to do a lot of weird floats or worrying about the height or anything like that. I can just go ahead and apply the classes, and I am done.
Now, the rules for nesting grid layouts differs from one system to another, so be sure to thoroughly explore the documentation and the syntax of whatever grid system that you choose.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 101391 Viewers
61 Video lessons · 88160 Viewers
71 Video lessons · 71989 Viewers
56 Video lessons · 103809 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.