Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
So our CSS is really coming along here. We have some good structure built and our header has taken shape. It's changed a little bit since you've last seen it and then I have this vertical bar added here which I added with a border-left on the H1 tag and this mailmark added in the upper-right by giving a background image to the page wrap, this graphic here. So now it's time to dig into the Sidebar and specifically the navigation. Now, you can see we're looking at this page on the web that our navigation is way down here.
Now, that's not where we want it of course. We want it to be up here. We want our whole Sidebar over here on the left block, and the main content here in a bigger area on the right. We can accomplish that layout pretty easily just using float left and float right on those two things. Our sidebar is called an aside. We'll make it float left and we'll give it a width of 275 pixels. Now, our main content is float right, and we'll give it a width of 500 pixels.
So if we save that and go back out to the web it's going to look broken, fair warning. Where did all the white go? Very weird. It's because our parent container collapsed upon itself. Now, when a parent contains floated items like that it doesn't know how to calculate its own height and it just basically falls into nothing. Now, there're a few different ways you can handle it. My favorite way is by using what's called the clearfix. All one word. If you want to learn more about specifically how it works, you can google it.
Pretty easy to find but I'm just going to copy and paste it into this code and we'll look at it. Now, it has a class name of group. Could be anything, could be clearfix if you want it to be. I like group just because I like that word. It kind of makes sense to me. It means it's wrapping multiple things. Now there is some backslashy stuff in here. That's just ensuring that it's going to work in all browsers. So to use the clearfix we have to apply this class of group on the element we want to clear and in our case it's the page-wrap.
So let me add a class of group to this page-wrap, and you'll see if we refresh in the browser, we're going to be all good. Now, I've got to save the CSS file for that to take effect. We're all good. No problem. So we have our sidebar in place here. I mean, it's tucked up underneath the logo, but we can fix that with just a little top padding on the aside. So we'll apply padding here. Remember it's like a clock. We'll say 70 pixels on the top, but nothing for all the rest of the values for now.
That pushes it down just wherever you want it. Now, each one of these is a link. So let's look at our Photoshop file and see what we are trying to match. We want to be able to click anywhere in this block and go to the appropriate page that this is navigation for. So let's make this whole block our anchor link, and let's take a look at the HTML that makes that area. It's this here, down here. So it's within the nav tag, within this unordered list, within these list items.
These anchor links are what we're trying to style. So in the CSS we kind of follow the trail there. nav ul li a. We'll make them display block because anchor links by their nature are in-line elements, and we'll start just describing what we're seeing here a little bit. There's some padding on each of them. Maybe 10 pixels all the way around. Except for in the left it's a little wider, so I'll say maybe 25 pixels for that value.
The color is white. The font size is a little bigger than the default. Maybe 16 pixels. Text-decoration, we're going to set to none, anchor links by default are underlined, so that's going to get rid of that underline for us. We'll just give it a background color. Maybe just some dark gray for now and we'll deal with this coloring here in a minute. You can see that they're set apart from each other a bit, maybe 5 pixels. So none on the top, none on the right, 5 pixels in the bottom, and none on the left.
That's how those shorthand properties work. I'm going to hit Save. We'll go back up to the browser to see how we're doing. So, pretty good, not bad. We do have these little bullet points that are coming from the list. We should get rid of those. Those come from the list itself. So if we say nav ul, list-style none, and reload the browser, those will go away, no problem. Looking pretty good. Let's handle the coloring and do a little thinking in Photoshop here for a minute.
So there's four navigation items right now on top of each other and they kind of follow a nice color pattern, from blue to a little bit lighter blue, to yellow, to a green to kind of a muddy yellow. I think if we were to switch some of these things around, and we've got to be smart and assume that maybe our client will someday want to switch these things around, I think the color pattern that's going on here is more important than the specific tie between what the link is and the color. So we kind of want to color in the right order no matter what.
We're going to do that in a special way by using the nth-child selector. So you notice that they're all grey now, and instead of having them be gray, we'll have the default be with that top one, is this blue. So let's grab this blue color and replace this. We're going to say the background-color is that blue, and then we'll reload the browser, and they're blue. Now, we want to target the second one, just the second one only.
I am going to sample the color there, grab that color code from the color picker, and then say nav ul li and we'll use this nth-child selector, it looks like this, and say we just want number 2. The second one. So that anchor link within that, we want to have a background color of this that we just sampled. Let's check that out in the browser. Second one got the color perfectly. That's how you can target individual elements depending on their position.
So we have two other positions to deal with. So let me copy and paste the CSS there and say three and four and then copy those color codes from Photoshop as I sample them. Copy the green. Copy the yellow color. We'll go to the web and see how we're doing. Pretty good! Pretty good, perfect! Looking very good! Now, in Photoshop, another thing, the last thing we need to deal with are these little kind of nubs that stick down, giving us that ribbon effect, that kind of 3D effect there.
We're going to need a separate HTML element to deal with this. So let's jump over to the HTML and give us that element. It could be anything. We're just going to give it a span. I am just going to chuck that right within the anchor tag on each one of our menu items. It gives us a little bit of a thing to play with there. So let's go ahead and save that, and we're going to want to target it uniquely. So let's say nav ul li a span.
We're going to position them absolutely, so we can target exactly where we want them to be and remember when we use position absolute, the parent of it needs to have position relative so we can kind of make sure that it's relative to what's going on here. Otherwise if we give it position absolute, it'll be relative to who knows what? Maybe the body or who knows. So we'll make sure that the anchor tag has position: relative. It's not going to move it.
It's just going to set the context for us and then we want to position it with a right value of 100%. So no matter what, as wide as this thing is, we're going to start counting at the way left edge here. That's what right at 100% is able to do, and the top value of maybe 5 pixels will push it down, and give a width 15 pixels, and then a height of however tall that anchor link was, 100%. So let's just give it a background color of that blue for now that we used as the default and see how we're doing in the browser.
Very good! We've got the nub sticking out here, but they're all blue. So let's deal with that coloration first. All we have to do is just copy this selector, put a comma so it's kind of a multi-selector, put a span after this, so that it will share the color properly, and we'll do that on all three of these. Save it, and reload, and now we have the color working out nicely.
It's just that the color, they just bleed into each other. We need to give it that 3D effect. That little shadow that sticks out. So let's jump into Photoshop and make that shadow just a really tiny little box. 12 pixels wide, 10 pixels tall, and I'm going to go ahead and zoom-into it so you can see real close what's going on. I'll double-click the Background layer to unlock it, select all and delete the white that's by default there, and now this has a transparent background. I'm going to grab the Gradient tool.
Make sure that I have black selected as my color, and then make sure that our gradient is on the second one in here, this foreground color to transparent, and then hold Shift, and kind of just drag a little bit of background in here and then knock down the Opacity maybe to 40% on that layer. I'm going to save this image out as a graphic called navshadow. Jump back over to our CSS. We're going to use that on the spans, so it's going to have a background image of url(../images/navshadow.png).
We're going to make sure that it's positioned on the right, starting at the top, and it's going to be able to repeat vertically. Let's hit Save and see how we're doing there. Great! Now, we have that shadow giving it that 3D effect in the navigation. So that's the CSS for our navigation. Great start as we move forward with our CSS.
Get unlimited access to all courses for just $25/month.Become a member
61 Video lessons · 104231 Viewers
56 Video lessons · 116165 Viewers
71 Video lessons · 85377 Viewers
131 Video lessons · 40882 Viewers
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.