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.
Borders can add a great deal of flexibility to your menu styling. You can use them to indicate a current menu item, define the actual regions of your links, accent your links in multiple ways, or as we're going to do in this exercise, help create visual separation between the link elements. So we're going to be working once again on vertical.htm, this time from the 03_06 folder-- although we're really just sort of picking up from right where we left off again. All right, so in the last exercise we created a little bit of visual space using margins, and if I flip over to the browser, you can kind of see how this is working.
We've got a bottom-margin applied to all of these list items. The problem here, of course, is that the background color of the page is shining through, and that's not always going to be appropriate. So, what I'm going to do is I'm just going to come down, and I'm going to replace the bottom-margin here, and I'm going to do a border-bottom. So you're free, of course, to apply borders all the way around the links if you want to. But in terms of the way I want this particular menu to look, I just want a little bit of visual separation between each item. So here, we're going to do a very thin link, we're going to do 0.125 ems.
Now, don't worry too much about the math, the browser will do it for you. Just remember that 1 em is typically worth about 16 pixels based upon the default size of most browsers, so that's what I used to arrive at that particular value. Then I'm going to do solid-border, and then we'll do a color of white. So we'll go ahead and save that. Go back out to the browser, refresh the page. You can see the links are much tighter together now. The border is not quite as wide as the vertical margin that we had going on there before, but we still have a nice, clean separation or a visual indication of the difference between the links, which is perfect for what we're doing with this menu.
Now, one thing I do want to point out, you'll notice that we only applied the border on the bottom. If you did a border to both the top and the bottom, those two would combine to form a border that's twice as thick. So they wouldn't collapse as they came on the table, they would literally just butt right up against each other, and you would have two borders applied, instead of one. We're actually going to take advantage of that particular property a little bit later on when we create sort of a beveled effect on one of our menus. But for right now, just keep in mind that, that's the reason we only did the border on the bottom of it. We're using borders here to create a visual separation for links.
But I really want to encourage you to think about some of the other ways that you can use borders to enhance the styling of your menus. Also, keep in mind that borders are a part of the box model. So, any borders that you add are going to increase the width and the height of your menus. That's really important to remember when you're dealing with very tight layouts.
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.