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

Creating a different menu design for small screens

From: WordPress: Building Responsive Themes

Video: Creating a different menu design for small screens

When dealing with responsive menus, especially for smaller devices like phones and tablets, you may need to think of providing alternate styles rather than just resizing or reorganizing of layouts. Even though a menu might be easy to click on with a mouse, it might be harder to click on when you use your thumb or your finger on a touchscreen device because the menus generally are really small when you have them on a regular screen. If you look at the original design, you will see that I intended the menus on smaller screens to be these large buttons that are below the main header so that they're separated clearly menu items and they are easier to click on.

Creating a different menu design for small screens

When dealing with responsive menus, especially for smaller devices like phones and tablets, you may need to think of providing alternate styles rather than just resizing or reorganizing of layouts. Even though a menu might be easy to click on with a mouse, it might be harder to click on when you use your thumb or your finger on a touchscreen device because the menus generally are really small when you have them on a regular screen. If you look at the original design, you will see that I intended the menus on smaller screens to be these large buttons that are below the main header so that they're separated clearly menu items and they are easier to click on.

So what I want to do is create new styles in the media queries that completely restyle the menu in the page. I will show you how I do this by using the Chrome Developer Tools. By using the Chrome Developer Tools, I'm able to experiment with the live code on the page and then I can change only those elements that need to be changed and nothing else, to make my style code as short as possible. The first thing I am going to do is reduce the width of the screen until I hit that point where I want things to change.

Then I'll use the Developer Tools to identify the area I want to change. The first thing I want to do here is change the background color to white, because I know that I want all this area to be white. So I will go and identify the entire area, which is the ID access down here, and then I see the media query has already kicked in here, so that's where I want to add my changes. The first thing I want to do is add a new background color, so I will say background:fff, which is white. And now I see the white kicks in; however, the menu is floating in the space sort of.

I want the menu to span all the way across and all the way to the bottom. The reason why it's floating in space is because the menu is further contained by this divider that's called header_margin, and header_margin adds 20 pixel padding around the whole header. So what I need to do is override what header margin is doing. So I will go back to access and I'll add some extra style code. I will say margin and then I first want to add some extra space at the top, so I will say 20 pixels. And then I'll set the right bottom and left margins to -20 pixels to override the styling from header margin.

So I will say -20 pixels for the right, -20 pixels for the bottom, and -20 pixels for left. And now you see the menu appears to hover underneath the main header, even though it technically is still part of the main header. And of course, you can't see the buttons right now, because they are white, and we will get to that in a bit, but first I want to save what I just did in my actual style sheets. I will highlight it here. I will go to my style sheet and find that style. It's all the way here at the bottom, inside the media query for 719. And here we have access.

So I will simply replace access with the new code I created, clean it up a bit, and then I will also make a comment for myself so I know what's going on here. Save it, reload the page, and now the menu is at the bottom. The next thing I need to do is make these menu items visible again, so I will select one of the menu items and then look at the styling that affects it, and I see here, under access a, that the color is set to white.

So if I just go and change that to #333, for example, I get this nice gray color instead, so that's probably what I need to do. In addition, if we look at the design, you will see that these menu items have padding on the top and on the sides. So I will go and add that padding. So I will change the padding here from what it is, to 10 pixels on the top and bottom and 25 pixels on the left and right. So now you see my menu items are much larger.

So before I do anything else, I am just going to save this. I am going to create a new style called access a, with a new padding and a new color. So I go down here again, add access a, padding: 10 pixel, 25 pixel, color: #333333, and close the style. I will save that, reload the page to make sure it works, and now we have those elements in the right color.

However, you see that the hover state is white, and we don't want that. So, I am going to go back and add that hover state as well. So I will go access li:hover > a, and access li:hover > focus, then set the color to #000, which is black.

Now you may wonder why I am using this code, access li:hover, to a, instead of saying access li: hover. That's because in this theme you have a dropdown menu, and you want the style to also take effect if the dropdown menu is activated. So I will save this, reload the page again, and now you see, if I hover over the menu, you get a subtle difference in the color of each of the items. Going back to the design reference again, we see that we also have a border around each item.

So I will go back, and I will find the list item, and I see that in addition to adding the border, I also have to get rid of that extra margin. So first I will set the margin to 0. That way each of the menu items stacks closer together. And then I will set the border-right to 1px solid, and the color #e5e5e5, and I'll copy that style out and set border-bottom to the same thing.

Now you see we have a nice clean menu that appears where it is supposed to and that also reorganizes as we scale the screen up and down. So I will copy out the style, find access li:, and replace it, clean up a bit, save it, reload the page, and here we have a fully functional responsive menu that only pops in when the screen gets small enough.

Now, there are a couple of additional things you need to do to make this menu responsive. In particular, you also need to address the dropdown elements. So what I've done is, in the exercise files for this course, in the code_snippets, you will find the complete code snippet for this movie so that you can add all the additional styles. It's not that many, but there is a couple. So if you go down to movie 6.2 and you simply add in all the style code here, jump menu down, all the way down to access ul ul, and replace what you just did, save it, and reload the page, you will get the same result and now the menu will work perfectly in all scenarios.

By providing a separate style set for smaller screens, you can create a whole new look and functionality for the menu without having to touch the underlying markup in the process. Pretty nifty, right?

Show transcript

This video is part of

Image for WordPress: Building Responsive Themes
WordPress: Building Responsive Themes

39 video lessons · 16943 viewers

Morten Rand-Hendriksen
Author

 
Expand all | Collapse all
  1. 4m 5s
    1. Welcome
      1m 4s
    2. Using the exercise files
      1m 27s
    3. What you should know before watching this course
      1m 34s
  2. 8m 36s
    1. What is responsive design?
      4m 16s
    2. The different faces of WordPress on mobile
      1m 55s
    3. Exploring the finished Anaximander theme
      2m 25s
  3. 9m 38s
    1. Getting and installing the Anaximander theme
      1m 53s
    2. Configuring basic theme options
      7m 45s
  4. 23m 51s
    1. Deciding what screen sizes to design for
      4m 11s
    2. Thinking responsively: Designing for many different screen sizes
      6m 23s
    3. Visualizing content realignment for better markup
      4m 35s
    4. Designing menus
      4m 52s
    5. Adding responsive images and videos
      3m 50s
  5. 26m 8s
    1. What are media queries and how do they work?
      4m 18s
    2. Exploring CSS3, progressive enhancement, and graceful degradation
      3m 27s
    3. Understanding best practices for media queries
      3m 57s
    4. Creating a responsive frame
      5m 12s
    5. Customizing media queries with the Chrome Developer Tools
      5m 28s
    6. Taking device width into account
      3m 46s
  6. 11m 1s
    1. Resizing the site title and the description
      8m 22s
    2. Adding media queries to the header
      2m 39s
  7. 11m 22s
    1. Making the menu responsive
      3m 35s
    2. Creating a different menu design for small screens
      7m 47s
  8. 19m 22s
    1. Making a responsive single-post layout
      6m 11s
    2. Making images responsive
      4m 37s
    3. Making videos responsive by including FitVids
      8m 34s
  9. 7m 45s
    1. Making the sidebar responsive
      5m 10s
    2. Hiding sidebars on mobile
      2m 35s
  10. 7m 28s
    1. Dealing with footer widgets
      5m 11s
    2. Adding navigation links that return to the top of the page
      2m 17s
  11. 12m 54s
    1. Using FlexSlider to create a responsive slider
      6m 2s
    2. Creating a loop to show sticky posts in a featured slider
      6m 52s
  12. 24m 37s
    1. What is jQuery Masonry?
      3m 41s
    2. Installing jQuery Masonry
      4m 45s
    3. Configuring the index page with Masonry
      7m 0s
    4. Using CSS to finalize the Masonry layout
      6m 17s
    5. Adding media queries to the Masonry index
      2m 54s
  13. 9m 11s
    1. Exploring hidden features of the Anaximander theme
      5m 51s
    2. Where to go from here
      3m 20s

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.

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 WordPress: Building Responsive Themes.

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.