Drop-down menu under response

Source: Internet
Author: User

Original: Convert a Menu to a Dropdown for Small Screens

Conversion menu is drop-down to fit small screen

Translator: Dwqs

Five Simple Steps (PS: called FSS) website has an elegant responsive design feature, when the browser window is changed into hours, the top right corner of the menu is converted from one line of the rule to a drop-down menu. (PS: Originally written in 2011, the design of FSS website has changed, can be referred to the original text.) )

Html

The HTML code for the two menus is different, because so far you can't design the <select> and <option> styles to have the same look and behavior, and vice versa. So both of them need to be designed, and all you have to do is write the two marks. The FSS practice is as follows:

<nav>   <ul>     <Li><a href="/" class= "Active">Home</a></Li>     <Li><a href= "/collections/all">Books</a></Li>     <Li><a href= "/blogs/five-simple-steps-blog">Blog</a></Li>     <Li><a href= "/pages/about-us">About Us</a></Li>     <Li><a href= "/pages/support">Support</a></Li>   </ul>     <Select>     <option value="" selected= "Selected">Select</option>         <option value="/">Home</option>     <option value= "/collections/all">Books</option>     <option value= "/blogs/five-simple-steps-blog">Blog</option>     <option value= "/pages/about-us">About Us</option>     <option value= "/pages/support">Support</option>   </Select> </nav>

Continue to the next

Css

By default we use Display:none to hide the Select menu, which is well accepted. For the screen reader, the extra menu will be hidden.

Select {  displaynone;}

Then take advantage of media queries, for some specific width of the sudden change. You can design according to the actual situation (standard breakpoint Reference)

@media (max-width: 960px) {  ul     displaynone; }  Select display: inline-block; }}

Do you need to maintain two menus now?

Well, that's a problem to worry about. Maybe your menu is dynamically created and you can't control the output well, maybe you have the technology to handle the menu but want to make sure that you don't accidentally sync up two menus. One way to find it is to dynamically create a drop-down menu from the start. With jquery, it's easy to achieve:

//Create the dropdown base$("<select/>"). AppendTo ("NAV");//Create default option "Go to ..."$("<option/>", {"Selected":"Selected","Value":"","Text":"Go to ..."}). AppendTo ("NAV Select");//Populate dropdown with menu items$("Nav A"). each (function() {varEl = $ ( This); $("<option/>", {"Value": El.attr ("href"),"Text": El.text ()}). AppendTo ("NAV Select");});

Then make sure the drop-down menu can be used

$ ("NAV select"). Change (function() {  window.location = $ (this). Find ("option: Selected "). Val ();});

is the drop-down menu a bit abrupt?

A little. Small screens are mostly mobile devices, and their support for JavaScript is friendly, so don't worry too much. But if you want to make sure it works without JavaScript, you can refer to my other article: I have a article about that.

Effect Demo: http://jsfiddle.net/Web_Code/j810jta8/embedded/result/

Package Download: http://download.csdn.net/detail/u011043843/8257615

Original starting: http://www.ido321.com/1348.html

Drop-down menu under response

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.