CSS: Frameworks and Grids
Illustration by John Hersey

Nesting grids


From:

CSS: Frameworks and Grids

with James Williamson

Video: Nesting grids

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.

Start your free trial now, and begin learning software, business and creative skills—anytime, anywhere—with video instruction from recognized industry experts.

Start Your Free Trial Now
please wait ...
Watch the Online Video Course CSS: Frameworks and Grids
3h 27m Beginner Jan 22, 2013

Viewers: in countries Watching now:

Have you wondered if using a CSS framework will speed up your site development? In this course, senior author James Williamson introduces the types of frameworks available—including the most popular choices among working web developers—and provides an honest assessment of the pros and cons to using a framework. He guides you through downloading a framework, setting up a directory structure, and building a framework-based site, such as structuring the HTML and working with forms. A separate chapter explores layout grids, often included with CSS frameworks, which provide a simple system for laying out page content.

Topics include:
  • Understanding boilerplates, grids, and frameworks
  • Choosing a framework
  • Building your own framework
  • Crafting a deployment strategy
  • Modifying files
  • Customizing typography and color
  • Filling in framework gaps
  • Exploring grid-based syntax
  • Nesting grids
  • Using mobile grids
Subjects:
Developer Web
Software:
CSS
Author:
James Williamson

Nesting grids

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.

There are currently no FAQs about CSS: Frameworks and Grids.

 
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ .

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Join now Already a member? Log in

* Estimated file size

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed CSS: Frameworks and Grids.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member ?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferences from the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

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.

Learn more, save more. Upgrade today!

Get our Annual Premium Membership at our best savings yet.

Upgrade to our Annual Premium Membership today and get even more value from your lynda.com subscription:

“In a way, I feel like you are rooting for me. Like you are really invested in my experience, and want me to get as much out of these courses as possible this is the best place to start on your journey to learning new material.”— Nadine H.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.