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.
Although we've created the initial structure of our page, our content currently has no semantic meaning at all. In fact, without actually examining the content itself, there's no way to establish the role of the content regions or how they relate to each other. Now, actually from a layout view, that doesn't really matter. Layouts can be created using whatever type of elements and whatever organization that you want. Semantic value doesn't really play into CSS page layout at all. However, leaving out this information would not be a very good practice, and it would make it very difficult for anybody parsing our code to figure out what's going on.
So with that in mind, we're going to add some organization and meaning to our page by using the class and ID attributes. Now if you've watched any of my other titles, you've probably heard me say that I often see designers make the mistake of simply using class and ID values for styling. Now, while they are certainly acceptable for that--you can use them as styling hooks if you want-- their real role is to help organize and identify contents. So, let's see what they can do for us in our page and towards that end, I have the index.htm file open from the 02_06 directory. And it really is just sort of picking up right where we left off in our last movie. Okay.
So, the first thing I need to do as I'm beginning to organize this is figure out, number one, whether I need a class or an ID and then what I want the name of that class or ID attribute to be. All right! So, the first thing we're going to do is we're going to go ahead and add a little bit more information about our header content. So, I'm going to go right inside the opening div tag there and I'm just going to create an ID attribute, and I'm going to give it an ID attribute of pageHeader. Okay, so let's talk about the difference between IDs and classes. Now IDs are unique, and that doesn't mean you're only allowed one ID per page, but I can only have, at this point, one element on my page named pageHeader.
I cannot use that ID attribute again on this page. I can use it throughout my site to be consistent and say, okay, this is the page header on this page, and this is the page header on the next page, but on this particular page, I can only have one page header. So, when I'm trying to decide whether something should be a class attribute, which you can use classes over and over and over again on the page, or whether it should be an ID attribute, the question that I pose is, is the only time that I'm going to have this type of element on the page? And I'll only have one page header. Now, the article on the page might have its own header, the sidebar might have its own header, but in terms of the header for the entire page, this is the only one.
So in that sense, it makes sense to use an ID for that. Using the same type of reasoning, I'll go into the next div tag and I'm going to add another ID. This ID is going to be mainNav. Now, the name that you use for your different elements in your regions is really up to you. And if you're working in a team environment, it's a really good idea to come up with some naming conventions throughout your site, so that everybody is using the same names, or is at least coming up with names using the same formula. You'll notice, for example, that I'm using what we call CamelCase syntax to name these, which is if I add more than one word, first word is the lowercase, every other word after that will be upper case, and they're all sort of jammed together.
You can certainly use underscores, but you can't use spaces. So whatever name you give your IDs and your classes, they need to be a single word. Okay. So, I'm going to keep going. I'm going to go to the div tag that's sort of surroundings this container div tag that's surrounding all of my content, and thinking of it that way gives me a really good idea for what the ID attribute for that's going to be. I'm just going to type in "ID," and the ID for this is going to be content. Perfect! Okay, now when I go to the banner, I'm faced with another decision: Is it possible in this site that I might have more than one banner on a page? I can think of times, for example, where I might want a banner that is more informational, like this one is where it just says information about the site, and I might have another banner that is promotional, and I might have an ad in it, or I might have more than one banner with ads.
So in this sense, I can probably see this site having a page that has more than one banner on it. So, instead of using an ID for banner, I'm going to use a class, and my class is going to be just that, banner. Okay, perfect! All right! I'm going to finish this up by going into each of the additional elements here. The div for my article, I'm going to go ahead and give that an ID. The ID that I'm going to give that is home. It's the homepage article. So I'm just going to call it home. On other pages I might give the article a specific name specific to that particular article or the subject of the article. In this case, it's going to be home.
For the sidebar, I'll go ahead and give it an ID of sidebar. And then finally, footer, you can probably imagine what that's going to be. I'm going to go ahead and give that an ID of pageFooter. So, very much like the header, the header's page header, this is going to be page footer. That's the other thing. Other elements, other articles might have their own individual footer; this is the footer for the entire page, so I'm going to go ahead and give it an ID of pageFooter. So, now, really anybody that reads through our code, even if I deleted the contents of the div tags themselves, would understand almost immediately the structure of our content and how it all relates to each other, so what the relationship of the content is.
Now, we've used classes and ID values to extend the meaning of our code, and that's going to make our pages easier to author. It's certainly going to make them easier to organize. And consequently, all of that makes it easier to style our content. So, if you have really well-structured, well-organized pages, they're just a lot easier to style. Now, in our next movie we're going to take this a little bit further by seeing how HTML5 can help us add even more meaning to our code.
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.