New Feature: Playlist Center! Pick a topic and let our playlists guide the way.

Start learning with our library of video tutorials taught by experts. Get started

CSS: Styling Navigation
Illustration by

Solution: Creating a vertical menu


From:

CSS: Styling Navigation

with James Williamson

Video: Solution: Creating a vertical menu

I hope you had fun going through the Vertical Menu Lab. Let's compare your finished files with mine, and discuss each of the steps for a lab as we go through the code. So I have actually opened up the index.htm and the main.css file from the finished_files folder of the 03_09. And remember, the CSS file, the main.css is actually in the _css subdirectory. So we're just going to jump right in and go through all of these steps. All right, so for the first step, you needed to go into the CSS reset and add the ul and li elements to eliminate any of the default margins and padding from those lists.
Expand all | Collapse all
  1. 3m 8s
    1. Welcome
      42s
    2. What you should know before watching this course
      1m 12s
    3. Using the exercise files
      1m 14s
  2. 35m 25s
    1. Organizing menus with lists
      4m 26s
    2. Ensuring accessibility
      9m 3s
    3. Using the nav element
      7m 30s
    4. Creating block-level links
      3m 8s
    5. Lab: Structuring navigation
      4m 11s
    6. Solution: Structuring navigation
      7m 7s
  3. 48m 42s
    1. Exploring link style considerations
      9m 2s
    2. Using global link styles
      9m 56s
    3. Styling link states
      10m 57s
    4. Indicating external links
      10m 4s
    5. Styling image links
      8m 43s
  4. 52m 5s
    1. Stripping default list styling
      4m 34s
    2. Defining link dimensions
      6m 0s
    3. Setting link styling
      3m 36s
    4. Aligning links vertically
      4m 11s
    5. Controlling link spacing
      2m 30s
    6. Styling menus with borders
      2m 32s
    7. Creating rollovers
      4m 45s
    8. Restricting link styling
      3m 31s
    9. Lab: Creating a vertical menu
      11m 44s
    10. Solution: Creating a vertical menu
      8m 42s
  5. 54m 58s
    1. Stripping list styling
      3m 35s
    2. Displaying links horizontally
      6m 14s
    3. Clearing floats
      6m 12s
    4. Controlling link sizing and spacing
      3m 11s
    5. Styling links
      7m 16s
    6. Creating rollovers
      5m 52s
    7. Indicating current pages
      4m 43s
    8. Controlling cursor states
      2m 46s
    9. Lab: Creating horizontal menus
      6m 45s
    10. Solution: Creating horizontal menus
      8m 24s
  6. 55m 35s
    1. Overview of dropdown menus
      1m 17s
    2. Structuring submenus
      5m 56s
    3. Styling submenus
      6m 4s
    4. Creating submenu rollovers
      3m 28s
    5. Positioning submenus
      5m 43s
    6. Controlling submenu display
      5m 5s
    7. Creating persistent hover states
      5m 53s
    8. Animating menus with CSS transitions
      6m 29s
    9. Lab: Dropdown menus
      6m 51s
    10. Solution: Dropdown menus
      8m 49s
  7. 58m 7s
    1. Creating CSS-only buttons
      8m 39s
    2. Creating special effects for buttons
      4m 2s
    3. Enhancing buttons with gradients
      7m 40s
    4. Overview of CSS sprites
      3m 30s
    5. Using CSS sprites for icons
      14m 30s
    6. Styling block-level links
      8m 38s
    7. Lab: Enhancing navigation with CSS
      5m 26s
    8. Solution: Enhancing navigation with CSS
      5m 42s
  8. 6m 29s
    1. Additional resources
      6m 29s

Watch this entire course now—plus get access to every course in the library. Each course includes high-quality videos taught by expert instructors.

Become a member
please wait ...
CSS: Styling Navigation
5h 14m Beginner Nov 16, 2012

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.

Topics include:
  • Organizing menus with lists
  • Creating block-level links
  • Styling links, link states, and image links
  • Defining link dimensions
  • Controlling link spacing in a menu
  • Creating rollovers
  • Clearing floats
  • Indicating current pages
  • Controlling cursor states
  • Building dropdown menus
  • Creating CSS-only buttons
Subjects:
Developer Web Web Design Web Development
Software:
CSS
Author:
James Williamson

Solution: Creating a vertical menu

I hope you had fun going through the Vertical Menu Lab. Let's compare your finished files with mine, and discuss each of the steps for a lab as we go through the code. So I have actually opened up the index.htm and the main.css file from the finished_files folder of the 03_09. And remember, the CSS file, the main.css is actually in the _css subdirectory. So we're just going to jump right in and go through all of these steps. All right, so for the first step, you needed to go into the CSS reset and add the ul and li elements to eliminate any of the default margins and padding from those lists.

So to do that, you were going to go down into the CSS reset, which is right here on about line 98 or so. I just went ahead and added the ul and li element selectors to the existing CSS reset. Now, if you put yours at the end and not right here, there is nothing wrong with that. I just like grouping elements together. Since I already had the ordered list there, I just went ahead and put those two right there in order as well. All right, our next step was to locate the info section styles, remember they were on about line 351 or so.

Now, in that section, our first item of business was to write a selector that targets all unordered lists in those info sections, and we were going to add some properties that would strip out all the default list styling and then set a margin for those using 1 em for the top, 1.2 em for right and left, and then 1 em for the bottom. If I go down into my code again here, around line 351 or so, this is the selector I wrote for that. So, I took a cue from the selectors above it, where we're doing an element-specific class selector, we're essentially saying that, hey, any section element that you find with the class of info applied to that, look inside that and find any unordered list.

So we're being very specific, but we're really tackling any section element that has the class info applied to it which for all of those little sections that we have in the finished_files, it's pretty much all of them. All right, we went ahead and set the margins, 1 em for top and bottom, 1.2 em for right and left. If you wrote that out a little bit and didn't use shorthand, there is nothing wrong with that. It will still work just fine. And the next thing I did was I went ahead and stripped out all of the list-style property. So I just went ahead and set them to none. Now, our next step was to target the list items inside this section.

So again, we have another selector that's doing that. We were supposed to set the bottom margin of that to 0.8 ems and then reset the font size a little smaller than the default size at 0.9 ems. So again, this is a selector that I used. If you did section.info ul li, that works just fine, but it's maybe one more element than you actually need. And then finally in this section, we were tasked to target all of the individual links with inside lists and change their display property to block.

Now here, we did have to go a little bit more specific with this selector, we didn't want to target all links inside these info sections, we only wanted to target a link when it was inside of a list, which is why I used the list item element selector in combination with that. So again, just setting that display property to block. That's going to take care of all of our sort of generic styling for lists within those info sections. Now, the next order of business was to find the styles that we're targeting, that one specific section that has a class of find.

And then what we were supposed to do there is write selectors that were specific for that section, that were going to affect the vertical menu that we were building. So I am going to scroll back down to find those, and for me, I think it's about line 443, yeah, or so. For you it might be a little different. If it is, it's not that big of a deal. Remember, the first step was to target any unordered list inside that specific section. And again, I am just taking cues from some of the selectors above this. I'm doing an element specific class selector. I am saying any section with the class of find applied to it, and I'm going to target an unordered list inside of that.

You may be asking yourself, wait a minute, what about specificity here? If you've dealt with specificity much, essentially it says the most specific rule wins if there is a conflict between the two of them. There's certainly a conflict between the info ul rule, and the find ul rule. But we've got one thing going for us here, which is this section is actually below the info section, meaning it comes later, and the last style applied wins. So in this case, we're using the cascade more than we're actually using specificity.

If you felt like you needed to write a lot more specific selector in order to get that targeting done, you don't really have to do that because it's a little bit lower on down your styles. Okay, so here we were setting our margins to 1 em for the top, 0.6 ems for the right and left, and 0.6 ems for the bottom. Again, if you didn't write the shorthand quite that way, that's fine, doesn't matter. Even if you did them all individually, still going to work just fine. The next thing we wanted to do was to strip out all the margins from the list items. So I just went ahead and did a margin of zero to do that within the selector, and then we want to create that bevel effect.

And remember, we were doing that by creating both the top and a bottom border, both of them were 1 pixel and solid, but then the colors were a little bit different. Remember, the bottom border got that sort of lighter blue, whereas the top border got this darker blue. Okay, now that's going to create that bevel effect, and if I switch over into my browser, this creates this bevel effect that you're seeing dividing the two of them, but of course, our top menu item and our bottom menu item don't need those borders, especially when there were only going to get like a top or a bottom one respectively so that the bevel effect wouldn't even apply there.

So, your next order of business was to strip those out from the top and bottom elements. And again, I just used the technique that we used in the very last exercise within this chapter. I used the first-child and the last-child selectors, I used both of them. And in the first-child, I told this border-top to be none, and in the last-child, I told the border-bottom to be none as well. Scroll down a little bit, we've got two more things that we needed to do, one was to find all of the menu items, in this case, that would have been the links inside the list items, inside that section and then just add a little bit of padding all the way around it, 0.6 ems worth of padding. Again, I just used shorthand notation here.

Then the very last thing was to create a rollover. And to do that, I just went ahead and did a generic a:hover inside the find section, and I left off the li. If you added the li there, that's fine, there's nothing wrong with that. That's actually probably a little bit safer than the way I did it. I just happened to know that within that one find out more about section, the only thing that's ever going to be in there is a menu. So in that case, I feel a little bit freer maybe to use selectors that aren't quite as specific. Again, we give it a foreground color of that orange, and then we were giving in a background using an image this time instead of a color, which is resulting in that diagonal pattern.

Now, I wanted to see if some of you guys were going to catch this. If I scroll up, and I take a look at any of these other sections, a couple of them have links, and if I scroll over those links, I happen to see that exact same pattern. So, I did this on purpose. I wanted to see if you guys were really reviewing the styles or not and seeing whether you were paying attention to some of the global styles that were placed before that. If I go all the way up into the Global Styles, and I start looking at this one selector right up here that says a:hover, so every single link in the entire site starts out with that background pattern on hover, and I will override it in some places, and I won't on others.

So if you were checking through the styles, you would have seen that, and you would have said, hey, you've already got that applied, you don't necessarily need it. So we didn't really need it there, it's not hurting anything by being there. So, certainly don't feel like you have to rush to take it out. But it was one of those things where I was just checking to see if you were paying attention. We don't really need that. If I save this, go back into my browser, and refresh it, I notice that when I come back in here, I still see the pattern. So in that sense, no harm, no foul. So, I know there was a lot to that lab, creating vertical menus as we did throughout the chapter before that, that's rather straightforward.

However, I wanted to point out that integrating one into the fabric of a larger site is a totally different task. Now, I hope this lab has helped you not only understand how menus are styled, but what you're going to need to do as you organize, and write the menu styles as a smaller part of your larger overall site.

There are currently no FAQs about CSS: Styling Navigation.

 
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.
Upgrade now


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

join now Upgrade now

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed CSS: Styling Navigation.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

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.

Are you sure you want to delete this note?

No

Notes cannot be added for locked videos.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.