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.
Welcome to your first lab. Now in our labs you get to put what you've learned up till this point to the test. They are little different than regular exercise files, because instead of me giving you step-by-step instructions, I am going to give you the overall goals for the project, and then it's up to you to decide how to solve the problems that I give you. After you're done working on your lab, be sure to check the solutions movie that follows this one to compare your solutions to mine. So for our lab on floating, go into the 03_10 directory and open up the index.htm and the main.css file.
Now I want to preview this page in a browser and I am going to compare it to the finished version so you can see kind of what our goals are. So here's the page in its current state. If I scroll down, after the banner some things start to appear maybe not the way we want. We are still in a single-column layout. We've got these two boxes that are stacked vertically. Our Archived Galleries list is way too wide. So obviously here our layout is in a single column instead of the two-column layout that we are shooting for. If we look at the finished version of the file, if I scroll down, you can see that this content is now in a column on the left-hand side, our Archive Galleries are a column on the right-hand side.
They look a lot narrower. They look a lot better like that. These two boxes are stacked horizontally now, and then there are our page footer. So that is what we are shooting for. Now I am going to go back into the code and talk about what explicitly we are going to need to do. Okay, so I am going to focus on the main.css file. At the very top of the CSS file, I have in a comment the goals of your lab, so as you're working through the lab, feel free to go back up to these and take a look at all of your goals in order. Now I am just going to go down through the code and sort of show you, in the code, where you are going to be writing certain selectors and which selectors you are going to need to modify to achieve what we want.
All right, so I am going to go down to about right around line 160 or so. I have got a section on the styles right here that says, "Basic layout styles." Currently right now there are only two selectors in there, so we are going to have to add some stuff to this. Now the first thing that you need to do is you are going to need to write a selector for the body that's going to set the overall width of the page to 1280 pixels, and then you are going to need to use that selector to center the entire layout. Go back through. We didn't have a specific movie on centering, but in many of the movies in this chapter, I talked about using a technique with margins to center content on the page, so that's kind of what we are going for there.
Now the next thing we will need to do is write a selector for the article tag, or the article element, that makes it the left column in our two-column layout. You need to give it 50 pixels' worth of space on the left-hand side, and it should take up a total of 900 pixels' worth of space. Now after you are done with the article, write a selector for the aside that makes it the right-hand column in our two-column layout. Now for it, it will need 50 pixels' worth of space on the right-hand side, and then I want its total width that when it's added to the left-hand column, leaves you with 50 pixels' worth of space between the columns.
So you are going to have to do a little math here. Think about this. Your left-hand column is going to take up a total of 900 pixels' worth of space. Your page all total is 1280 pixels wide, so essentially, the right-hand column will need to have 50 pixels' worth of space on the right-hand side and then 50 pixels' worth of space between the left and the right-hand column. And you are going to need to decide exactly how wide that's going to need to be. The last thing here that I'll need you to do is the page footer. We want to ensure that the page footer always remains below our two columns, so you are going to need to modify that selector so that that occurs.
Now I am going to scroll down to right around line 332 or so, there we go, and find the news selector. So this is those two boxes that are stacking currently right now, vertically on top of each other, but in the finished version, they are stacked horizontally. That's what we need to take care of. So we are going to modify the news selector so that the two news items are going to appear horizontally. We are going to use margins to separate the two so that there is 50 pixels' worth of space between them. Here's the tricky part though.
You've got to make sure the spacing only appears between the two news items and doesn't create additional spacing on either side. Now what I mean by that is if you were to go ahead and apply just margin right to both of them, then you end up with instead of just 50 pixels between the two of them, you've got another 50 pixels on the other side. So you've got to figure out how to solve that. That could require an extra selector. Maybe you could do it with just a selector, but you might have to write an additional selector as well, and that's something that you're just going to have to really put on your thinking cap about and try to solve that particular problem.
My advice is to take a moment before you start this, look through the HTML and the CSS--I know there's a lot of code here--and get familiar with the elements that you are going to be controlling. It's always more difficult to modify somebody else's style sheet rather than your own, so I realize I'm putting you in the middle of a difficult situation here. So think about how you can use floating to achieve the goals that I just talked about, and then carefully plan on how you are going to use padding and margins to achieve the desired spacing in your elements as well. So you should use padding in this instance. You should use margin; that's something you are really going to do need to think about.
Now as I've stated throughout the chapter, there's going to be multiple ways to create the desired layout using floats, so don't get too caught up in trying to guess exactly how I did it. Simply decide for yourself what the most efficient way is to solve the problems that I have given you. Have fun!
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.