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

Lab: Dropdown menus

From: CSS: Styling Navigation

Video: Lab: Dropdown menus

In our final lab we are going to take the Roux Academy website and create dropdown menus for several of the main navigation links. Though Roux Academy dropdowns are going to be a little different from the dropdowns that we built in the previous exercises, it's been pretty common when we do a lab that you're building something that's almost exactly or identical to what you're building in a previous exercises. And in this lab, I wanted to stretch you a little, I wanted to take you a little outside of your comfort zone and say, okay, you know the techniques. Now let's see if you can make them work in a slightly different way.

Lab: Dropdown menus

In our final lab we are going to take the Roux Academy website and create dropdown menus for several of the main navigation links. Though Roux Academy dropdowns are going to be a little different from the dropdowns that we built in the previous exercises, it's been pretty common when we do a lab that you're building something that's almost exactly or identical to what you're building in a previous exercises. And in this lab, I wanted to stretch you a little, I wanted to take you a little outside of your comfort zone and say, okay, you know the techniques. Now let's see if you can make them work in a slightly different way.

So let me show you what I mean. In the Roux Academy website, when I start to mouse over these top-level items, you'll notice we have dropdown menus for several of these that show up. But instead of showing up as a vertical menu like we did in our exercises, these are showing up just like another horizontal menu. They are just sort of underneath that. There's a little bit more to these, let me show you what I mean. If I click on say the programs page to go to the programs, here are the options in the programs menu submenu. But when I mouse off of it, it doesn't go away, it persists, which is perfect, that's exactly what I want, because if somebody's within the program section, I want them to be able to go up and see what their options are.

However, notice that these menus are semi-translucent. So if the other submenus were to lay on top of this, that would be a problem. You would have a hard time reading these. So notice that as soon as you go up to the menu bar and start mousing around, the other sub-navigation menus come up, but when you leave the navigation bar, the appropriate pages sub-navigation comes back and persist. All this is being done with CSS and without JavaScript. As far as the positioning of the menus go, as far as this nice subtle animation that we have that fades these in, you're going to be in control of all of those things.

Now in terms of these menus persisting on their section pages, I am just going to talk about that a little bit when we get into the solution of the movie. So let's jump in and take a look at our lab instructions now. I have the index.htm file, as well as the main.css file open from the 05_09 directory. Remember that the main.css file is actually in the _css directory. We've got a few steps here. The first thing that the steps are telling me to do is what we just did. Basically, open the finished file, preview it in the browser, play around with the menus for a while, get an understanding of how they're positioned, what they look like, what kind of transition are evolved so that you've get a better idea of what you are going to need to do in terms of styling.

And then the next thing I'm asking you to do is to take a look at the HTML of the sites pages and really become familiar with how the submenus are structured and how classes are assigned. We are going to take a look at that once we're through all the steps. Here are the lab steps. I am just going to browse through these. First thing you want do is scroll down in the main.css file and find the dropdown menu styles. They are around line 252 or so depending upon which code editor you might be using. I need you to write a selector that's going to target the submenus. I am not telling you what selectors are right, you are going to have to figure exactly how to target those submenus based on the structure of html.

If you want to, you can use the surrounding selectors to kind of give you a hint. Now here's what I need you to do within that selector. You need to turn floating off, you need to set the background to this semi-transparent white color, and I have provided you with that value. Figure out how wide the submenu needs to be, based on where it's going to be located and then assign that value, set its height to Auto so that the contents are actually controlling the height of the submenus. And then I want to use positioning to start the submenu way off the page. I have given you -9000 pixels, but you can choose whatever you want to.

And then I bring it back to 45 pixels from the top of the parent nav element. You should also disable any margins. The next think you are going to do after that is you are going to use the structure of the top-level menu and the submenus. You are going to use that structure to write a selector that repositions the submenu to align with the nav element when the submenus top-level menu item is hovered over. So you'll need to write that selector, and you'll need to trigger that. Then using opacity, fade in the submenu as a trigger, and I want that to animate. You want to fade those submenus in as they are triggered with the top level menu items.

Inside the submenus themselves, that default rollover color for links of orange is very hard to read against that white background. So I am going to change it to one of the other site's other colors, which are sort of a darker lavender color, and I have given you that color right there. So you're going to go in to the submenus and change that rollover color for the submenus themselves. The last thing I want to do is just sort of observe test those dropdown menus and take a look at what I was talking about earlier. When you navigate to one of those sectional pages that has a set of submenu links, that submenu is going to persist until you hover over the nav bar again.

Try to figure out how that's done, read through the CSS, locate the selectors that are controlling that, and then I want you to really think about how that structured and the approach to that. I want you to really think about the selectors and say to yourself, is there more efficient way to do this without using JavaScript? One last thing that I want it to do, I am going to go to the source code of index.htm, and I want to show you how these menus are structured. At the very top of everything is a nav element with an ID of pageNav has a class of cf, which is just clearing it, so you're not necessarily going to use that to identify anything, and ARIA role of navigation.

The top level unordered list has a class of topmenus, very similar to what we are doing earlier, and then all of the submenus also have that class of submenu as well. Something that's very important, it's not really going to have any bearing on the way you write your styles, but for that last step where you are going in and you are really sort of taking a look at the persistence of the submenus. I am going to open up one of those files, I am just going to go ahead and open up admissions, which is one of the sections that does have a submenu, and when I go down into admissions, I want you to notice that not only does the link have a class of current, but the list item has a class of current as well.

So as you are looking through those rules to try to determine how that menu persists when you're not browsing over it and how it goes away when you browse back over the nav bar, pay attention of that, that's a very important clue. Another thing as you go through the rules down here--and I am just going to scroll down to show you where these dropdown rules are going to go, as I mention around line 263-- you are going to see that a lot of these rules are already kind done for you. I have got a lot of selector already written and in place.

And the reason for that is I really wanted you to focus on the three most important tasks for dropdown menus and the ones that are likely to be newest for you. Number one is overriding the default menu styles, number two is properly positioning the submenus and then finally controlling the dropdown display. So those are the things I really want you to focus on, and that's particularly what your tasks are targeting. And as always, be sure to watch the solutions movie once you finish to compare your finished menus with mine.

Show transcript

This video is part of

Image for CSS: Styling Navigation
CSS: Styling Navigation

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

Learn more, save more. Upgrade today!

Get our Annual Premium Membership at our best savings yet.

Upgrade to our Annual Premium Membership today and get even more value from your lynda.com subscription:

“In a way, I feel like you are rooting for me. Like you are really invested in my experience, and want me to get as much out of these courses as possible this is the best place to start on your journey to learning new material.”— Nadine H.

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.