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.
With the additions of margins, borders and paddings, we've come pretty little far way in terms of making our design look like what the designer wanted. But there are still some things that need to be addressed as an example of the date near the upper right-hand corner, that the designer count for October 26, 2005 is supposed to be on the navlinks bar and not below it as it is right now. The about tea history has a white box that's supposed to extend all the way out to the left side of the design and not line up with the legendary origins of tea and the rest of the content in the content column, and the tea of the today in post archive headings, those are supposed to go all the way out to the edges of their respected boxes, and that's not happening right now either.
So we need to fix that. There are a variety of ways we could go about this we can try to take the about tea history heading and move it out of its content column so that it's not pushed over along with the rest of the content column, but that really means rearranging the document structure just to create stylistic effects, and I always try to avoid those if at all possible. Similarly try and get that July 16, 2006 or basically get the date up into that bar. That could be a little tricky.
We can do it let's say with floats but then we'd have to figure out how to get one float to sit over the top of another and that doesn't really work very well and we could try to float it and not have the navlinks be afloat but then we'd have to move the date to be before the navigation links, and we can't restructure hacking. What we can do instead is for these things is use a little trick, a little negative margin trick. We're going to start this, basically I'm going to start this by saying margin top zero because as it stands right now the space between the July 16, 2006 text and the element above it, that's the top margin on that paragraph.
As it turns out it's a 1em top margin. So if I set that to zero, then as you can see here the date snuggles right up against the navlinks, but that's ok, it's closer but it's not what we wanted yet, but if we change this top margin to be negative, so we actually say, let's say, negative 1em then what's going to happen over here is that's just going to keep getting pulled upward. The whole paragraph is actually a paragraph containing this date and it's just being pulled upwards, further and further, thanks to this negative top margin. So we have it into the bar it's not exactly where we want it, but visually we've got it into the bar, structurally, nothing has changed of course, but visually we're getting it very close to where we want.
And now the last thing is just to find the right distance for this to move as it turns out that's about 1.66em, if we hit Reload, there you go. It looks vertically centered in the bar but that's because of that negative top margin. So that's the way to use negative margins, you basically use negative margins to pull things out and pull things over each other. It's a little visual trick, but the nice thing is that we didn't have to go and hack through the document structure and created a two cell table or something like that, just to put one thing next to another.
We didn't have to worry about that at all. Similarly for that h1 in the content, instead of having a right margin of zero we're going to try a right margin of minus 2em, which pulls it on out. Now, digging into the style sheet it turns out that the left margin of the content div is 3em, about tea history is one and a half times the font size of the rest of the content div, so with a negative 2em left margin it gets pulled the same distance as that space. So everything lines up nicely and if you look back, we also had a right and left padding of 2em, which is exactly equal to the distance of the negative margin there, which is why the a in about tea history lines up with the rest of the column.
I didn't mention that when I gave it 2em padding in the last video, but now you know, I was thinking ahead a little bit. So we're going to use a similar approach for the the sidebar headings, the tea of the day and post archive. With these guys I'm just going to say margin, no top and bottom margins, -0.8em and if we hit Reload they spread out very nicely. 0.8em, why that, because the h3s have a font size of 1.25em and 0.8 times 1.25 equals one, and that equals the 1em right and left padding on the divs in the sidebar. Now, having done that as you may have noticed, now the text and tea of the day and post archive is gotten jammed all over the side and we don't want that to happen. So here we'll change the left and right padding on the guys to be exactly equal to the negative left and right margin that we just set and tadaaaa! There they go. We can fit that a little bit should we so choose, but that gives us the result we want so why not run with it.
Now there is one more thing to point out here, which is the body element, the body, the document, whatever you want to call it. There is this quote, unquote gutter space around the entirety of our design here. You can see this most easily around the sides and the top of the masthead where there's just this blank space, it's been stuck in between the edges of the browser window and the design. This is a browser default. Pretty much every browser that exists today has this default. Interesting thing is, that's typically implemented as a style on the body element, and almost every browser in the world does it as a margin, but there's an argument to be made and some browsers accept this argument, that that's actually padding on the body. Frankly, I think that that's correct.
That really is body padding, a body margin, but that's not what other browsers have done, it's not what most browsers have done, so the way that we get rid of that in as cross browser and the safest way possible is to say body, margin zero, padding zero, and having done that, if we go back and reload, see everything moves out, there's no separation now between the design and the rest and the edges of the browser window, and we have things looking pretty darn much like they appeared in the designers comp.
So that's the fun that you can have with negative margins and zeroing out certain margins. In the last video we're going to talk about margin collapsing, which is a little bit of a technical issue, but it's, it's important to understand, so that you can understand why certain things happen in web browsers.
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.