Start learning with our library of video tutorials taught by experts. Get started
Viewers: in countries Watching now:
CSS: Page Layouts introduces basic layout concepts, gives advice on how to create properly structured HTML based on prototypes and mockups, and goes into critical page layout skills such as floats and positioning. Author James Williamson shows how to combine these techniques to create fixed, fluid, and responsive layouts. Designers are also shown how to enhance their pages through the creative use of CSS techniques like multi-column text, opacity, and the background property. Exercise files are included with this course.
In the previous movie, we began the process of planning a sample two-column fixed layout. We established the target resolution, we decided which unit we were going to base the grid off of, and we defined our grid. So in this movie, we are going to complete that process by using the layout grid to determine how to space our columns and then calculate the element dimensions we will need for our CSS. So I am just going to keep working in the fixed_planning.ai. In the previous movie, if you opened up a layout program and worked with that, then you can just continue doing that. And if you grabbed a piece of sketch paper and you are sketching it out on that, then that's awesome. Just keep doing that.
The first thing I want to focus on is the main column. Now I have already mentioned how this layout is going to be text heavy, so that means that wherever the body copy or the main text is, that's the most important content region on the page, and that is where I typically like to start with my layout. I am going to bring up something that as an art major I tried to avoid for years and years and years, so just give me a moment. Yes, there it is; the calculator. As an art major, I try to stay as far away from math as possible, but it finally caught up to me again. So in terms of spacing columns, we really have to think about readability.
One of the things that you learn if you study typography is that the ideal column width for readability is about 66 characters wide. So if you can make a column that's around 66 characters, that's really the sweet spot, somewhere around in there. Now a character is typically one half of an em, so 0.5 ems. So if our base unit is 16 pixels, that would be the default size of our text, I am going to use 8, I will multiply that by 66, and that gives me 528.
So that is the initial target for my main column, which is going to be on the left-hand side, for our particular layout, 528 pixels. So I am going to go back into my layout program, and I've sort of done myself a little favor here. I have given myself some starter blocks to work with. That's the magic of editing; it's sort of like owning your own cooking show. You can just put something in the oven and you are ready to go with it. So here is my first initial containing block, and I am just going to go ahead and make that 528 pixels wide, and I will just make it 1200 pixels tall to match the rest of our layout.
So let me get control over this thing. I am going to line it up right here with our layout grid, and you can see it just sort of lines up. The thing that I have to think about here is, remember, when we set up our grid, we're basing this off of a 12-column layout. So you can see these heavy gridlines right here are those columns, and there are 12 of them over the course of my layout. That means that my content regions really need to line up with those columns. So what I want to do here then is grab this and just move it out until it lines up with the nearest column, in this case which is right here, and if I'm counting that, that's 1, 2, 3, 4, 5, 6, 7 columns.
If you are thinking to yourself, "Oh, but James, you had it perfect. It was going to be 66 characters long." Remember, number one, that's just an approximation. If you get close to that, that's fine. That's kind of a starting point for us. We have to have everything that we are doing based off of the grid that we are building, so it's okay. Plus, the other thing to remember is that there is going to be some padding inside this and there'll also be some margins between the two columns, so this isn't exactly the width of the content; this is the width of the column, and those are not always the same thing. Now what's really nice about this is since we are doing a two-column layout, the other column is already defined for us now.
So I am just going to take little guy and move him over and then once that's lined up-- let's go ahead and move this over as well to line that up-- now just so I can keep who is who straight, I am going to go ahead and grab that color, so that I have two different color columns. So this is the very beginning of our two-column layout. We have one region that's based off of seven columns of our layout and we have another region on the right- hand side that's based off of five. Oddly enough--and I promise you I did not plan this, this way; it's just kind of worked out when I was doing this.
I was like, huh, the 7:5 ratio is actually part of the golden mean. So if you are familiar with the golden mean as a ratio, 7:5 works out to that. So it should make a very pleasing layout once we are finished with this. Once I have sort of these regions blocked out, now I need to think about what is the actual width of these going to be? So if I click on this particular column, I can see that that column is 560 pixels wide, which means of course that this one is 400 pixels wide. So I am just going to grab this text.
I would normally make notes in my sketchbook, but here we are. So I am going to go 560 overall for this particular column and then this one of course is going to be 400. That's going to give us the overall container block width for these elements, but the container block width and the content width is not the same when you're talking about CSS, because we need to start factoring in spacing, such as padding and margin and things like that. So I am going to work with padding now, and I'm going to grab this little block right here-- yellow is a good color for padding--and I am just going to move this out right here and start working with that.
Again, I want my padding to be based off of my grid. A single gridline is 16 pixels, so I could use that for padding, but in the layout like this, 16 pixels is going to be really close to the edge. You are talking about, like, 1em. So I am going to go out to the very next gridline, and that gives me 32 pixels, and that's what I am going to use for my padding. So I am just going to change the height of this to 1200 to match everybody else, and that's going to shoot it way up there obviously. And then I am going to take it and align with the upper right-hand corner right there. Now I want the same padding on both sides, so I am going to place that over there, and then I have to think about the spacing in between these columns. How are these guys going to be spaced? I really like having a gutter that equals the padding on both sides, so I am going to grab this and then copy it over.
Now, do I want 32 pixels between them, do I want the spacing on this side? Actually, in this case, what I am going to do is I am going to split the difference. I want to put 16 on one side and I am going to put 16 on the other side. What that's going to do for me is it's going to keep that sort of ratio, that nice 7:5 ratio that I have got here going on, and not skew it towards one side or the other. So now I have padding on this side, padding on this side, and then the gutter between the two of them, which can be controlled through margins, it can be controlled through padding, or it can just be controlled through setting the element widths and floating one to the left and one to the right, just like we did in the last chapter.
But what I need to do now and what I will need to know for my CSS is okay, what is this going to do to the overall content widths? So if I grab these measurements, I am just going to come down here and say, okay, this is 32, this is 32, and that's 32. Now the rest of these obviously have to add up to 960 pixels, and we sort of have this overall width. So this 560, I would subtract 32 from it on this side, and I would subtract 16 for this amount of spacing right here.
So, if I bring this down, that's going to give me a total width right here of 512 pixels. I will do the same thing right over here. I have got 400 pixels, and I'm going to have to subtract 48 pixels from that, so that's going to give me a total width here of 352. Again, I am not great at math, but 352 pixels wide. So in essence, what we are doing right now is we're writing our CSS.
We know we have a column on the left- hand side, we know we have a column on the right-hand side, we know the padding values of those columns on the left and right side of the respective columns, we know the width of the columns, and we know how much spacing we need between the two of them. Now if I wanted to, I could go ahead and throw some headers and footers in here and just as part of the exercise here, if I were to do that, I would want that header based off of the grid. So if I draw a header here and then let's just make it a little bit more palatable by making a little lighter, I would need to think about how tall I want this header to be. And because I have this snapping to the grid, I can just say okay, along which gridline do I think it's going to be appropriate for my header? And a lot of that of course is going to be what's up there.
In this case, I am just going to go ahead and create a header of 128 pixels. Notice it's still based on that grid line and now for my header, at least I know what the height of the header is going to be, and the height of the header here is going to be 128 pixels. So I'm fond of saying, and you have heard me say this throughout the title, that a lot of times I know what my CSS is going to be before I ever open up my code editor, and I hope this gives you some idea as to kind of what I am talking about with that. I know that I am going to have a header, I know that I am going to have a left column and a right column, I know how tall the header is going to need to be, I know the amount of padding that's going to be on either column, and I know the amount of space that I want between the two of them.
So that gives us a fantastic starting point for our fixed-width two-column layout. Now I am betting that based on everything we have covered up to this point, you probably have a pretty good idea of what our initial HTML structure of the file is going to look like, and what the initial styles are going to be as well, and we are going to test that out in our next movie as we write the styles for our layout based on the grid that we've just created.
There are currently no FAQs about CSS: Page Layouts.
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.