Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Structuring submenus

From: CSS: Styling Navigation

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.

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.

Show transcript

This video is part of

Image for CSS: Styling Navigation
CSS: Styling Navigation

53 video lessons · 17161 viewers

James Williamson
Author

 
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

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
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.


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 Already a member? Log in

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 preferences from 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

Your file was successfully uploaded.

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.