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

Organizing menus with lists

From: CSS: Styling Navigation

Video: Organizing menus with lists

Before we begin working with CSS, I want to take some time to look at structuring site navigation properly. HTML and CSS work hand in hand, and you want to make sure that you start with clean, well-structured HTML. We'll start that by structuring a menu. Now to do that, I have the menu.htm file open from the 01_01 folder, and as you can see, there is not a lot going on, on the page here. We just have a series of links inside the body tag one after the other, Home, Products, Blog, About, Contact.

Organizing menus with lists

Before we begin working with CSS, I want to take some time to look at structuring site navigation properly. HTML and CSS work hand in hand, and you want to make sure that you start with clean, well-structured HTML. We'll start that by structuring a menu. Now to do that, I have the menu.htm file open from the 01_01 folder, and as you can see, there is not a lot going on, on the page here. We just have a series of links inside the body tag one after the other, Home, Products, Blog, About, Contact.

If these were scattered all the way throughout the site, obviously they wouldn't be related to each other at all, but when they are in this order here, when they are one right after the other, people will begin to infer a specific meaning about them. Let me just show you what I mean by that by switching over to looking at this page within a Browser. So here up at the top of the page, now we can see Home, Products, Blog, About, Contact. Most people are going to assume--and correctly in this case--that this is a menu. Now, menus are related groups of links. They mean something to each other, in this case, it would be our site's navigation of the Home page, Products page, Blog, About, Contact, so sort of the main pages of this particular small little site.

The problem here isn't so much the visual aspect of this. We could style this any way that we wanted to right now. We could take these links, and we could apply background colors to them and space them apart and create rollovers, and it would look just like perfect site navigation. Now, the problem here right now lays in the structure of the HTML. If I go back to the code, you can see that there is nothing here really telling any type of user agent that these links are related to each other at all. To do that, we need to add a little bit of semantic structuring to these links that basically groups them together. So we have a couple of choices here.

I mean, we can certainly wrap them inside of a paragraph, we can wrap them inside of a div tag, but those are limited in terms of their structural ability. They basically just segment the links as belonging to a certain section of content. They don't really say that these links relate to each other in any definable way. The best way to do that is to use a list. Lists are perfect for menus. As we mentioned before, menus are really simply a list of related links. So it would make sense to use a list to represent that. So, what I am going to do is right after the opening body tag, I am going to go ahead and create an unordered list tag, and then at the end of these links, I will close that out.

And then for each one of these anchor elements, I am going to go ahead and wrap them in a list item tag. You're going to want an opening list item and then a closing list item that's going to surround each one of these anchor links. Now, in doing this, we're basically semantically saying, or structurally saying that these links are related to each other. We're not really passing any additional information about how these links relate to each other right now, but at least we're defining the fact that these links belong together, they relate together, and they are part of a list.

So if I save this and go ahead and preview that into my Browser, I can see that there is a pretty big change here. Actually, this throws up a little bit of a roadblock to us stylistically, because now we're going to have to make basically these links look so that they are not part of a list when we structure our site menu. However, structurally, they are exactly what we need. And since we have more control over our presentation than we do the page structure, you want to make sure that the page structure is correct. We used an unordered list here, but that's not always going to be the case.

Now, I would say it is certainly the most widely- used list type in terms of representing menus, but there are times when an ordered list would be appropriate. Let's say that you had a menu that describes the steps for doing something, maybe that you have links to individual steps within a recipe, maybe you have links to individual steps of registering for a website. Well, those would be represented better by an ordered list so that if the user agent doesn't support styles, there is a distinct order to those links that you want to pass along to the user. In this case, there really isn't a distinct order to the links.

If we were to shuffle these around, it really wouldn't harm the menu at all, so an unordered list is certainly appropriate. One more thing about structuring menus with lists, not only do we get this really nice semantic structure, it also gives us multiple styling hooks that we can use. For example, here we have the unordered list tags, and then we have all these individual list item elements that we can style as well. Now, that gives us a distinct advantage when it comes time to style our menus.

Show transcript

This video is part of

Image for CSS: Styling Navigation
CSS: Styling Navigation

53 video lessons · 17001 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 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

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.