Start learning with our library of video tutorials taught by experts. Get started
Viewed by members. in countries. members currently watching.
CSS gives Web designers control over the appearance of their web sites by separating the visual presentation from the content. It lets them easily make minor changes to a site or perform a complete overhaul of the design. In CSS Web Site Design, instructor and leading industry expert Eric Meyer reviews the essentials of CSS, including selectors, the cascade, and inheritance. The training also covers how to build effective navigation, how to lay out pages, and how to work with typography, colors, backgrounds, and white space. Using a project-based approach, Eric walks through the process of creating a Web page, while teaching the essentials of CSS along the way. By the end of the training, viewers will have the tools to master professional site design. Exercise files accompany the training videos.
In this video we're going to add padding, having done margins and borders, already as you can see we have in our style sheet and now we're going to put some padding on things. Now padding is the space between the content of an element and the border. And it's part of the background area so any padding we add the background of the element is going to extend into that padding. A good example of this is with the navlinks, that purple bar that we've got going across the top. We'll give that let's say half of em of padding on the top and the bottom and three ems of padding on the side. If we reload, there you go, the navlink bar is gotten larger that half of the padding on the top and bottom, basically pushes extra space between the content area, which is where all those list items and links are, the about us and brewing and so on, and the edges of the background area. In technical fact, paddings between the content edge and the inner border edge. So if we had a border around the navlink here, then the padding would actually be the distance between the content and the inside of that border. We don't have that. We're going to see that in a moment when we do some padding in the content.
This is also how we're going to push those borders apart from the links. Right now we have those vertical separator borders that are jammed right up against the right edge of each of the list items, so, it's just simple padding right of, in this case we're going to go three quarters of an em, hit Reload, there you go. They push apart, have these lovely separators between each of the links. You might wonder why do we have a right margin of half em and a right padding of three quarters of an em and that's actually an interesting question. The reason being that the white space between each of these list items, counts for a little bit of space.
So that carriage return or line feed if you prefer in tab that I have highlighted there creates a little bit of a separation between the contents of two list items and experience has shown me that that tends to be about a quarter of an em, so the right margin of half an em, plus the cord around that sort of intrinsic white space handling separation comes out to about a three quarters of an em, which is why when you look at the borders, they seem to be centered between the base for the link text in each case. So we can just keep going with that for the homelink link which is what it is time to write.
we can give it a couple of ems of top padding and no right padding and a half em of bottom padding and 1em of left padding, just like that and then if you look at the Javaco tea a bit, and extends outward and suddenly the mass area is taller. Also the background area gets taller and notice the white curl image there in the upper right hand corner of the strain that's actually a background on the homelink link. We're using padding to make that hyperlink bigger, so that we can see all that background image. If we used margins instead of padding here then be background area would be smaller, because margins don't extend the background area, only padding does and so we might have that background image get cut off.
So that's why we're using padding there. We can continue on with adding some padding. For example, the content each one here, which is the one that has the weight box around it, we might give it a similar lead to the navlinks, a half an em of top bottom padding and a couple of ems of right and left padding and then the h2. That's the one that has the green bottom border underneath it. We're going to use some bottom padding to push the border away from the content of the h2.
So when we go back over and hit Reload, you'll see that the white area around about tea history is going to get larger and the border is going to push itself away from The Legendary Origins of Tea text, just like that. That's that half em of padding helping us out on The Legendary Origins of Tea, giving us something that's pretty much like what we saw with the designers comp. so only the about tea history is sort of spread apart and we're not done with those things we actually in an upcoming video, we'll talk a little bit about how to finish up the last polish points, but for now this is how we're going to make this work.
So let's go back and actually add a little bit of padding over in the sidebar. If you look over here, there's no padding around the form. Basically the text input in the search box in the form element is just shrunk wrapped around basically the the contents there, and the same thing with the tea of the day in the post archive headings are very sort of constrained and for that matter, if you look at the interior of the tea of the day box, where it says Labrador Tea and it's got some text, that stuff is all grayed up against the edges of the div that's creating that box. We don't want that. We actually want to push those in a little bit so there's visual separation between the contents and the edges of the box. We probably want to do that even if that weren't what the comp calls for, just because honestly this just doesn't look very good and that's, it's kind of annoying to read, so we want to fix it anyway, and that's what we're going to do. For the form we can give it some all around padding with the 8/10 of an em or 4/5 of an em if you prefer, and then for the divs we're going to give them no top padding, some right and left padding and some bottom padding.
Now, the reason that we do want to give them any top padding, if we go back to Firefox, if we gave them top padding, that would push the tea of the day in the post archive headings downwards and would put gray above them and that's not what we want according to the designers comp. We just what to push things inward and the bottom padding will prevent things like you can see here, where the tea of the day picture is jammed right up against the bottom of that div box. That's actually not such a bad effect in my opinion, but it's not what the designer called for. If you look in the comp, you can see that the designer has space set out there so we want to recreate that and this padding of 0 1em 1em will help do that, and if we reload, there you can see, we've created some extra space.
But wait a minute you say, those headings just got pushed inward, post archive in the tea of the day. Yes, there's really no way to say, apply padding to all of the contents of this element except for the ones I don't want to, you can directly say that in CSS but you can fake your way around it and we're going to find out in the next video. For now we're just going to have to accept that that's the state of things and will take steps to overcome them later. As for why we used eight tens of an em for the form, that just seemed to be about the right amount when compared to the visual comp. The comp actually looks like there might be slightly more than that and we can fit it with that if we like, we can say, well maybe 0.8em then maybe that's good on the sides and maybe we want one quarter em on the top and bottom and we'll just go and we'll reload and maybe that's a little better. The nice thing about CSS of course being that you can just go to the style sheet, fill it with some numbers, you know, do some trial and error if you like it and it really doesn't cost you a whole lot to do that. So there's really only a couple more things I'd like to do here before we move on to the next video. One is to add a little bit of padding to those h3s, that would be the tea of the day and the post archive. I want to get some top and bottom padding cause if you look again in the comp, they're nice and spacious and so I'd like to recreate that and here it is, just like that.
And then the last thing is at least in the sidebar is for this tea of the day, Labrador Tea, where it says Labrador Tea, if you look, it has a little bit of spacing and the top as well so we're just going to take care of that. And then the last little bit is just the footer, so that we can recreate as much of the space as we can, shown there, in the footer in the design comp, and so if you reload, you notice Labrador Tea kind of stretches out and there's the footer gotten all nice and tall.
So that's how you add padding. As I said before, there are obviously some things that we need to clear up like the space around the post archive, the tea of the day headings and also for that matter of a fact that the about tea history white box doesn't go over to left as far as it should according to the design comp, and for that matter, the fact that there's blank space between the edges of the browser window and all of the content, look around the masthead, the design comp, doesn't really want it that way, so we need to get rid of that and in the next video we're going to do all that stuff.
There are currently no FAQs about CSS Web Site Design.
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.