Viewers: in countries Watching now:
Join James Williamson, as he shows you how to create elegant menus, links, and buttons that help visitors navigate your site faster and more intuitively. The course covers creating structured navigation that is accessible and clean, styling links, and building horizontal and vertical menus with rollover effects. The last chapter reveals how to create stylish buttons with special effects and CSS sprites.
Our submenus are looking the way that we want them to, but we still need to address their rollover behavior. So I have the dropdown.htm file open from the 05_04 directory, and the first thing I wanted to take a look at was the existing style for our rollovers so that we could kind of see what it is that we will need to overwrite for our submenu. So I'm looking at the li a:hover selected here on line 68 or so. So we've got it setting the background of that darker brown color. We are giving it a height of 2 ems, but we are also adding 0.3 ems padding to the top for the rounded corners.
We are positioning it with relative positioning so that we can move it up by .3 ems, which is what the top value there is doing, and then we are applying a border radius of 0.3 ems for the two top corners. And all those were combining to form that sort of tab look and feel to them, well, that's great, but for submenus, it's not what we want, number one it's going to cause a submenu's items to change size when you rollover and which is going to disrupt the entire submenu, and of course we don't really need that tab structure.
So we need to be able to overwrite that. I am going to scroll down into my dropdown menu styles, and at the very bottom, I am just going to create a new rule, and this is going to be ul.submenu li a:hover. So again, we are targeting when any link is hovered over that's inside one of the submenu list items. Now inside that, I am just going to start overwriting some of those properties that we were just talking about. First thing I want to do is change the background color from that darker brown, because in our submenus, remember that's the foreground color.
So we want it to stand out, and we will just use that orange color that we already have on the nav bar, it will give a nice contrast between the brown, and it will keep the color scheme consistent. So that's going be #D5973C, and then we are going to set the height to 2 ems, which will make sure they are all the same height as the links when they are not being rolled over. We are going to set the padding-top to 0.2 ems, if you remember the top one had expanded that padding to allow for the tab up top.
I am going to set the top value to 0. Now, here is the reason I am doing that. I don't really necessarily need to change the positioning value because being relatively positioned, they are still within a normal document flow, so it's not like absolute positioning where it removes them. What I do need to do, though, is keep the positioning from off setting it up that -0.3 ems, which is what's happening above that. So I am just taking that top value, and I am overwriting that with 0 which is going to hold it in place. We need to get rid of that border-radius, so I am going to use border-radius of 0, and I can just use shorthand notation there and make it 0 all the way across, and that's going to take care of those curved borders on the top right and the top left corners.
So let's see how that works. I am going to go ahead and save the file. I will preview this in one of my browsers, and if I scroll down now and hover over the submenu items, that's exactly what I'm looking for. You can see the items are no longer shifting due to the change in height, we don't have that brown color, that's the same so we can actually tell when we are rolling everything now, and we don't have any rounded corner, so we are not getting that tab look. Our submenu is looking exactly the way we want it to, which is perfect. Now we just need to move on to talking about controlling the positioning of the submenus and controlling when it should and should not display.
There are currently no FAQs about CSS: Styling Navigation.
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.