Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Applying the grid through CSS

From: CSS: Page Layouts

Video: Applying the grid through CSS

Now that we've gotten the hard part out of the way--and trust me, the planning is definitely the hard part-- it's time to apply our grid to our layout using CSS. While we'll be using techniques like floats that we've already covered in previous chapters, we're going to see how our planning really pays off in making our CSS easier to write and how our typographic styles will tie in to our layout. So I've got the grid.htm file open here, and you can find that in the 05_04 directory.

Applying the grid through CSS

Now that we've gotten the hard part out of the way--and trust me, the planning is definitely the hard part-- it's time to apply our grid to our layout using CSS. While we'll be using techniques like floats that we've already covered in previous chapters, we're going to see how our planning really pays off in making our CSS easier to write and how our typographic styles will tie in to our layout. So I've got the grid.htm file open here, and you can find that in the 05_04 directory.

And there's just a couple of things that I need to do right off the bat. One is just sort of give you an overview of the structure of the page. If I scroll down past the styles here, you can see that we have a header, followed by a section with a class of col1. That has a lot of text in it. And as I mentioned before, this layout is very text focused. After that we have an aside with a class of col2, and at the very bottom we have a footer. So basic structure. And of course if I previewed the page in the browser right now, you can see design-wise, it is no great shakes, but the structure is there, and we know the CSS that we need to write for this. Okay.

I am going to scroll back up into my styles, and I've got on about line 28 here a little comment that says layout, and we are going to write the layout styles directly underneath that. Before we do that, we're going to modify the body tag, because remember, step number 1 in our planning process was to define a target resolution for our page and then come up with a value for that. So in the body selector what I am going to do is I am going to assign a width to the page of 960 pixels. Remember, that's our target size.

And then below that I am going to go ahead and center this content on the page. I am going to give it a margin of 0 for top, auto for left and right, and 2ems of margin on the bottom. Now, the only reason I am doing 2ems on the bottom is I kind of always like my pages to sort of float above the bottom edge instead of be snugged to it, in my opinion. It lets the reader know, hey, this is it, the scene and the content, nothing is being clipped off. So I am going to go down into our layout, and I am going to start coding. Now, as I mentioned before, we already know the measurements that we are going to be using, and I am going to flip back to the planning document that we were using in our previous movies, and here are all the measurements that we need for the elements that we are going to be styling on our page.

So we'll come back here, grab the measurements, and go back into the code. So the first thing we are going to style is our header, so I am just going to write a selector for our header. And on the first line here I am going to give it a background color. Now, this is a decision that was made off-site, so we didn't see this one being planned out. If you don't like the colors I am using, please feel free to substitute your own. So rgb value of 76, 67, 65, and then remember the semicolon. Then I am going to go down to the next line and I am going to give this a margin-bottom.

Now, that's going to separate the header from the content beneath it, and I am going to go ahead and give that a margin-bottom of 16 pixels. Since we are basing this off font- size, I could certainly give it a margin-bottom 1em, but again, I am just sort of reinforcing the fact that this is based off of 16 pixels, in terms of our grid. Now, for height, I am going to give it 96 pixels. And if you were thinking to yourself, hey, wait a minute, in the planning document, didn't you say 128? well, you've got to remember that padding plus height and/or width equals total height and total width.

So back in our CSS, 96 is for the height, and that tells us that we're also going to add some padding. And the padding for this is going to be 32 pixels top padding, and then 0 pixels for the right, 0 pixels for the bottom, 32 pixels of padding on the left-hand side. So the 32 and the 96 give us the 128 pixels total height that we need, and then the 32 pixels of padding on the left- hand side matches the 32 pixels' worth of padding that we want everywhere. So now we've defined our header and we're going to move on to our next element, which is our first column.

So I am going to write a selector for col1. Now, that's the class name that we used for this column. Since we only really have a section and an aside, I could use those elements that they are inside of as well, but since we have those class names available to us, I am going to take advantage of them. So this is col1, and I am going to float this to the left. Now, just like we learned in our last chapter, this is going to create a two-column layout, one column on the left-hand side, another column on our right-hand side. So this one is going to be floated to the left. I am going to give it a padding to the left of, you guessed it, 32 pixels and, again, if I am looking for our width, I can go back to the mockup and it tells me 512 pixels.

So on the next line I am just going to type in width and I am going to do 512 pixels and save that. I am going to scroll down a little bit more so you guys can see this a little bit better, and then we are going to go ahead and create the styles for our second column. So that one is .col2. That's a class selector for the second column. This one is going to be floated to the right. So again, this is going to help us create our two-column layout: one is going to be on the left-hand side, one is going to be on the right-hand side. Now, if I go back to our mockup, I can see that I need 32 pixels of padding on the right here and I need 352 pixels for its width.

So if I go back into my code, I go down to the next line, and I'll just go ahead and give it that width of 352 pixels. I'll give it my padding-right of 32 pixels, and then I am just going to do a couple of things here for typography. I am going to give it a font-size of 90%. I want the text in the sidebar of the aside there to be a little bit smaller than our body copy text. And I'm going to give it a line-height of 1.6, so there's a good amount of vertical separation between the text there. All right! I am going to go ahead and save that, and then we have one more element left to do and that is the footer.

So I am going to write a selector for my footer. I am going to scroll a little bit so you guys can see this a little bit better. Again, for our footer, we'll do a background color. Again, feel free to change this if you don't like the color that we are working with here. I am just going to do rgb. The value for this is going to be 100, 98, 102. Don't forget the semicolon. And then on the next line, we are going to go ahead and give that a height of 80 pixels. Now, I know we didn't put this in the mockup but, again, that 80 pixels, the height there is based off of that 16 pixels.

We don't have any content in our footer right now. Later on, if we put content in it, we would probably add a little bit of padding, and then we would have to adjust that height value. And then, because we're doing a two- column layout with floats, what do we need to do to the footer that we learned in the last chapter? That's exactly right. We need to go ahead and clear that footer, so I am just going to do clear: both and save that. So I am going to go ahead and preview this in my browser again, and when I refresh the page, I can see my two-column layout. The layout looks okay, but it doesn't look particularly tied together, does it? And the reason for that is that even though these elements are based off of that 16-pixel grid that we were working with, the text right now isn't.

So there's really nothing to sort of tie it together visually, and even though the columns are spaced the way we want them to, we're really not getting that sensation that this is all tied together. So it's not just about defining element widths; you really have to think about the layout as a whole. I am going to go back into my code and I am going to uncomment out these typographic styles. So there's a little beginning comment right beside the h1 there, and then if I scroll down, there's an ending comment at the bottom of it. Now, if I save these and go back into my browser and refresh, you can see that now that looks a lot better, a lot more put together.

It looks a lot more tied together, and that's because all of the typographic styles that I just enabled are also based off of that sort of 1em 16-pixel grid, so everything sort of ties together. Now, if you want to examine that in more detail, just go back into the code and go through all the styles that I created here. There's really not that many. There are just four styles. But go through, take a look at their font-size, take a look at the margins that we're using here, take a look at line-height and the spacing, run these calculations and sort of figure out how they tie in to the same 16-pixel grid.

So the majority of our layout is now finished, and let me ask you: How much easier is it to have that out of the way during the planning stages, so that you just come in here and you just plug in your values and you know your layout is going to work? That's why it's so important to spend the time that you need in the planning stage to make sure that everything with your layout is working as you intend it to within that grid that you defined. So for the most part our layout is done, but even though our layout is primarily focused on text, it doesn't mean that we won't occasionally have images or other types of assets that we're going to need to add to this page context.

So in our next movie, we're going to take a look at how to make sure our page assets are working with our grid that we've established as well.

Show transcript

This video is part of

Image for CSS: Page Layouts
CSS: Page Layouts

71 video lessons · 44156 viewers

James Williamson
Author

 
Expand all | Collapse all
  1. 4m 20s
    1. Welcome
      54s
    2. How to use the exercise files
      3m 26s
  2. 1h 39m
    1. Box model review
      8m 47s
    2. Calculating element dimensions
      11m 11s
    3. Understanding margin collapse
      7m 59s
    4. Calculating em values
      7m 41s
    5. Calculating percentage values
      7m 51s
    6. Normal document flow
      13m 3s
    7. Controlling element display
      8m 53s
    8. Using CSS Resets
      7m 11s
    9. Fixed, fluid, and responsive layouts
      9m 9s
    10. CSS debugging tools
      6m 46s
    11. Using the Firebug Inspector and the WebKit Web Inspector
      11m 5s
  3. 53m 15s
    1. Page design workflow
      3m 6s
    2. Page design tools
      4m 56s
    3. Determining page structure
      7m 18s
    4. Creating image assets
      8m 58s
    5. Creating initial page structure
      7m 3s
    6. Adding meaning with classes and IDs
      5m 23s
    7. Structuring content with HTML5
      6m 6s
    8. Building internal structure
      10m 25s
  4. 1h 36m
    1. Floating elements
      7m 50s
    2. Clearing floats
      7m 28s
    3. Containing floats
      7m 50s
    4. Clearfix technique
      10m 38s
    5. Floating inline elements
      14m 34s
    6. Two-column floated layouts
      8m 17s
    7. Three-column floated layouts
      11m 30s
    8. Column height considerations
      7m 3s
    9. Creating equal-height columns
      10m 42s
    10. Floats: Lab
      5m 25s
    11. Floats: Solution
      5m 21s
  5. 51m 42s
    1. Relative positioning
      7m 59s
    2. Absolute positioning
      8m 59s
    3. Fixed positioning
      4m 23s
    4. Controlling stacking order
      8m 31s
    5. Clipping content
      8m 21s
    6. Controlling content overflow
      5m 38s
    7. Positioning elements: Lab
      3m 59s
    8. Positioning elements: Solution
      3m 52s
  6. 48m 46s
    1. Design considerations for fixed layouts
      3m 28s
    2. Establishing the layout grid
      7m 57s
    3. Defining column spacing
      9m 30s
    4. Applying the grid through CSS
      8m 56s
    5. Creating grid-based assets
      8m 26s
    6. Grid design resources
      6m 22s
    7. Building fixed layouts: Lab
      4m 7s
  7. 44m 35s
    1. Designing for flexible layouts
      2m 30s
    2. Calculating percentage values
      8m 45s
    3. Setting flexible width values
      6m 6s
    4. Making images flexible
      8m 10s
    5. Setting minimum and maximum widths
      7m 24s
    6. Building flexible layouts: Lab
      4m 53s
    7. Building flexible layouts: Solution
      6m 47s
  8. 49m 36s
    1. Responsive layout overview
      3m 49s
    2. Using media queries
      7m 16s
    3. Organizing styles
      8m 39s
    4. Making content responsive
      8m 33s
    5. Mobile design considerations
      7m 32s
    6. Building responsive layouts: Lab
      4m 23s
    7. Building responsive layouts: Solution
      9m 24s
  9. 1h 22m
    1. Creating multi-column text
      6m 36s
    2. Using borders to enhance design
      13m 59s
    3. Rounding corners
      6m 56s
    4. Adding drop shadows
      10m 35s
    5. Working with opacity
      6m 8s
    6. Utilizing the background property
      15m 5s
    7. Working with CSS sprites
      7m 58s
    8. Enhancing page design: Lab
      6m 22s
    9. Enhancing page design: Solution
      8m 38s
  10. 6m 25s
    1. Additional resources
      6m 25s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
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

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: Page Layouts.

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 ?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

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.