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

CSS: Styling Navigation

Structuring submenus


From:

CSS: Styling Navigation

with James Williamson

Video: Structuring submenus

Before we can start styling our submenus, we first have to create them. Submenus are lists of links that are nested inside their parent menus. In order to properly style your submenus, it is critical that they are structured correctly. And let's take a look at how to do that. So I have the dropdown.htm file open from the 05_02 directory--I'll scroll down in the code a little bit so I could focus on our existing menu. We are going to have three submenus as a part of this: products, blog, and contact are all going to have submenu options.
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

Structuring submenus

Before we can start styling our submenus, we first have to create them. Submenus are lists of links that are nested inside their parent menus. In order to properly style your submenus, it is critical that they are structured correctly. And let's take a look at how to do that. So I have the dropdown.htm file open from the 05_02 directory--I'll scroll down in the code a little bit so I could focus on our existing menu. We are going to have three submenus as a part of this: products, blog, and contact are all going to have submenu options.

Structuring this is actually really simple, it's just a nested list but you've got to make sure that you are placing them in the right place. In the case of products, for example, what I'm going to do is I am just going to create a little bit of space inside the list item, and this is what's really important about this. You want your submenus to come after your link but still be inside the list item, you don't want to stay outside of it, and it's just another unordered list in this case. So all I am going to do is inside that list item, I am going to create an unordered list, and then I am going to go ahead and close that unordered list.

That's just a habit that I've gotten into over the years. Whenever I open a tag up that's going to have a lot of stuff inside of it, or multiple items inside of it, I'll almost always close it right off the bat. That way I don't forget to close it later on. So it's just a habit that I've gotten into. Inside this we are going to have our first list item, and it's just going to be structured exactly like the menu. Inside this list item, there is going to be a link, and this one is going to go href to laptops.htm. I am just going to give it a title of laptops and then the text is just going to read Laptops, then I'll close out both my list item and my link.

Now I'm a big fan of not typing more than I have to, so what I'm going to do is I am just going to copy this and then paste it down on the next line and just change the appropriate text. So in a place of laptops, we are going to have tablets.htm, the title is going to be tablets, and of course the text is also going to be Tablets, and I am just going to keep doing that copying and pasting. The next one is going to link to phones.htm, the title for that one is going to be smartphones, the text is going to be Smartphones.

Finally, we are going to have accessories.htm, that of course we're just going to give it the title of accessories, and then finally it will also say Accessories. So I am going to save this, and just to kind of see what this is looking like, I am going to preview this in one of my browsers. Maybe it's not exactly what we are looking for, but it's also not horrible either. There is the menu directly underneath my Products one. Of course, I want it to look more like a vertical menu, but we'll get to the styling a little bit later on. What's important is you can kind of see the structure of this, you can see that it's directly underneath products, it is a nested list inside of the Product list item.

We have two more of these to do, and rather than making you watch me type all two of these, I am going to use the magic of video editing. So hang on just one second, and just like that, I now have a finished menu with all of my submenus in there. Now just to show you where these are, just pause the video and type these in. We've got a submenu for blog, it's going to have the Recent articles, Archives, and Hall of fame, and then we also have a submenu for Contact, I'm going to scroll down a little bit to show you that one in its entirety.

And that one has Customer service, Register, and Technical support. So remember, they need to be inside the list item. The last thing we are going to do is I am going to identify all of the submenus with a class, and I am also going to identify the top menu with a class. Now that's going to help us out when we style our dropdown menus, but that's not the only reason we are doing it. I am actually doing it because it's nice and semantic, and it lets any other user-agent or person know when they are looking at the code what type of menu this is. So I am going to go up to the very top unordered list, and I am going to give that a class of topmenu.

And then for each of the submenus, I am going to come in and give them a class as well, and I'm just going to call it submenu. Through the use of a lot of the newer CSS selectors, we really don't have to use classes anymore when we're styling our dropdown menus. It used to be almost a requirement that anytime you wanted to do a dropdown menu you had to have a class attribute that would allow you to target those submenu elements. So again, we've got three submenus. You want to identify each of them with a class of submenu, and you want to identify the top unordered list with a class of topmenu.

But these days, we actually have a lot of really cool selector types that allow us to target specific items and really filter out what you're selecting. So we don't necessarily need to go that route anymore, and I've seen a lot of tutorials online where people will do dropdown menus and they'll say, well, you don't need to use classes anymore, and that's true, that's absolutely accurate. However, I continued these classes for a couple of reasons. Number one, it does make it a little bit easier for you to style. You don't have to rely on selectors that might not see support in some of the older browsers, but number two, it's just a little bit more semantic.

Now as you're looking through the code, it's really easy to identify when you're looking at a submenu versus when you're looking at a top-level menu. So that's the reason that I use classes. The structure of our menu and all of our submenus is now finished. We are ready to go ahead and start styling it now, but before we do that, I just want to reiterate that the most important thing for you to remember here is where you locate the submenus. Remember that you want to locate them within the list item that it represents and not inside the anchor element. If you fail to nest that list properly, it's going to result in not only invalid code, but it's also going to result in dropdown menus that are going to be impossible for you to style.

So make sure that you are paying extra attention to your page structure as you code your submenus.

There are currently no FAQs about CSS: Styling Navigation.

Share a link to this course
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.

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
Welcome to the redesigned course page.

We’ve moved some things around, and now you can



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.

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