Start learning with our library of video tutorials taught by experts. Get started
Viewers: in countries Watching now:
CSS enables you to control the look and layout of a web page much more precisely than you could with HTML alone, but it can be time-consuming to learn. In this workshop, expert developer Candyce Mairs makes styling a quick and easy process, walking you through the process of adding content to a web page and using CSS to position that content. Candyce explains CSS positioning concepts like the CSS box model, floats, and clears and demonstrates how HTML and CSS work together to create the look of your web page. By speaking the same language as the browser, you can learn to work with the browser to place content accurately and easily.
At this point in time, my web page has two divs on the page. I have a Header area, with an image inside of it, I have a menu area, with hyperlinks each on their own line, with some formatting properties. And I may want to change those formatting properties once I get the positioning done. But for now there are some basics plugged in. You can see they are spread out vertically. And they do look a little bit squished together.
But let me get my positioning piece in first. And then I can fine tune that formatting. So how do I add a positioning piece for the menu? While the menu is not positioned too badly right now, but it's kind of hard to tell what's going on. So what I'm going to do is get it set up for adding any positioning I want. And also give it a background color so I have some idea what I'm dealing with regards to this menu div. Let's do that first.
One of the things I want to do is I need to create a situation similar to the header. I have a Header ID up here attached to my div. Down here, I have a menu ID attached to this div. So, what I can do is copy this Header ID and place it below and just change the name. So, that is my menu ID and this specifies that it is an ID type selector.
I try and differentiate between these. Within ID selectors, I try and put only positioning properties. Within Tags or Classes, which are not addressed within this course, I tend to use those particular selectors for formatting. If I differentiate between the two, I seem to have an easier time. So I just created the menu Div. And it has a width but I think I need to give this a background color. So let me give this one a background color.
And I'll just make it green. I know the other one is blue so I should be able to differentiate now within this section. And I know my menu needs to be narrower than the page itself. And definitely narrower than the header, so why don't I make this 225 pixels. So I set that, just the menu itself, to 225 pixels in width. I'll Save my page and put it back in the browser. Let me see what happens. Let's put it in Safari.
That is definitely green. No doubt about it. But if I move this over a little bit, it's a little bit obnoxious in the green department, but at least I can see the div that I'm talking about, so I know how much space it takes up. Now what I said to do was make it 225 pixels in width. My letters are awfully squished together and that's being caused by this negative letter spacing.
So I can get rid of that, but I think this is still going to be way too wide. Let me drop this down, and I get asked quite often how do you decide what to start with? Well if you don't know just guess. You'll find half the time when you guess you get better and better at guessing. Now I wanted to make this one awfully wide to show you, which I did, so that's still a little bit wide. I'm going to be adding some padding on this left side. Because clearly this text is butting right up against the corner of this content.
I also have this little bit of space here between these Div tags, so I want to get rid of that. Although if I'm not going to have this a color, I may want to maintain that. For now, I'm not going to worry about this white space here because I'm not going to have it this crazy green. But let's adjust the other features. I'm going to add some left padding to this box. Now when I add Left Padding, or in CSS terms, it's known as Padding-left. What that is going to do, is expand or add to the size of the box in the browser.
So if I add 15 pixels of padding-left, I need to subtract 15 pixels from the width. This padding and the width now add up to 175 pixels, which is what I had before. I'll try it in Internet Explorer now, which is much harder to see in terms of the colors. I need to take that green color off. Another way to handle this instead of adding a color to entire box, what you can do is add a border instead. So, I can go down here and say Border, and I'll add Solid and within this area I'll just make it one pixel, black.
And I can actually just comment this area out within CSS. But I'll just delete it for now. Let's see what that looks like. We'll put it back in the browser. I haven't tested with Chrome in a bit. But let me go back to Safari. That's much easier to see what's going on. So what this did was add a one pixel border surrounding my box. So sometimes it's easier to just add that border do you can see what's going on instead of trying to figure out what color will work for that specific web page.
Especially if the page already has a background color, it can get tricky. So that size looks pretty good. Now my menu itself, I think these should be black. I think I'm going to set them to Georgia font, and let's see what else I'll get rid of that letter spacing. I don't think I need spacing the letters, but let me change this to Georgia, instead of Lucida Sans. Now because this font name has spaces in it, I need the quotes surrounding it. But since Georgia is just a single word, I don't need to add that. So I'll take a look at what it looks like in Georgia. I'm also going to eliminate my letters facing here and I could just comment it out, I'll just go ahead and get rid of it.
And the last piece I want to add is want the font color to be black so I can just say Color Black. That should make all of my links black and we'll take a look. Let me go into Firefox this time. That looks much more like the original design without the squished letters. They are spread out a little bit further. I want to add a little more padding on the left so that these can line up with my logo up above.
That's totally personal preference. I think I'll go ahead and do that. It's very easy. You're down to pixel size precision in terms of fine tuning. Which is a feature I love about CSS positioning so we'll put it in Safari and you can see it. 25 was a bit to much so I can probably go down 2 or 3 pixels. I'll set this to 23 instead test that one out.
Once you get working in CSS, you can see how easy it is to be bale to test these types of things. Wait until you can get it in the browser. Take a look, see what you think, and modify. It makes it very easy to shift things around a little bit. And fine tune when working in CSS positioning. Just like it's very easy to shift it using formatting in CSS. Now at some point I'll eliminate this border, but for now I think my menu isn't doing too badly. I may want some more space up above home.
But what I'm going to do is position my other columns first, and then I can always come back and set this up once I get those columns finalized. So there is the positioning piece for my menu.
There are currently no FAQs about Exploring CSS Positioning.
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.