CSS: Folding menu (striped) in response mode, css folding

Source: Internet
Author: User

CSS: Folding menu (striped) in response mode, css folding
Original article: CSS: Responsive Navigation Menu

CSS: responsive navigation menu

Translator: dwqs

Before writing, how to make a responsive drop-down menu: a responsive drop-down menu

Previously, I wrote a tutorial on how to make responsive mobile navigation. Now I have discovered a new technique to implement responsive menus without using JavaScript, but to use clear semantic tags in HTML 5.

This menu can align left, center, and right. Unlike the menus mentioned in the previous article, you need to switch between display and hide by clicking. It also has a tag to display the activation/current menu item, and it can work on all mobile platforms and all desktop browsers including IE.

First, let's take a look at the Demo effect: Demo

I. Purpose

The purpose of this tutorial is to show how to change the regular list menu to a smaller display drop-down menu.

This technique is very useful in navigation composed of many links. For example, all buttons can be compressed into an elegant drop-down.

Ii. Nav HTML Tag

<nav class="nav">    <ul>        <li class="current"><a href="#">Portfolio</a></li>        <li><a href="#">Illustration</a></li>        <li><a href="#">Web Design</a></li>        <li><a href="#">Print Media</a></li>        <li><a href="#">Graphic Design</a></li>    </ul></nav>

Iii. CSS

/* nav */.nav {    position: relative;    margin: 20px 0;}.nav ul {    margin: 0;    padding: 0;}.nav li {    margin: 0 5px 10px 0;    padding: 0;    list-style: none;    display: inline-block;}.nav a {    padding: 3px 12px;    text-decoration: none;    color: #999;    line-height: 100%;}.nav a:hover {    color: #000;}.nav .current a {    background: #999;    color: #fff;    border-radius: 5px;}

4. Center and right alignment

As mentioned above, the align attribute can change the alignment mode.

/* right nav */.nav.right ul {    text-align: right;}/* center nav */.nav.center ul {    text-align: center;}

5. Support for IE

In IE 8 and earlier versions, HTML5 nav tags and media queries are not supported. Introduce css3-mediaqueries.js (or respond. js) and html5shim. js to provide back-up compatible processing. If you do not want to use html5shim. js, you can use div instead of nav.

<!--[if lt IE 9]>    <script src="http://css3-mediaqueries-js.googlecode.com/files/css3-mediaqueries.js"></script>    <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script><![endif]—>

Vi. Response

Now the interesting part is the responsiveness of the media query menu. If you are not familiar with responsive design, you can read my previous articles on responsive design (subsequent translation) andmedia query.

At the 600 px breakpoint, I set the nav element to relative positioning, so that I can absolutely position the ul element. With display: none, I hide all li elements, but keep the current li element displayed as a block element. Then, when the mouse is hovering over the nav element, add the display: block to all the li elements. To mark the current li element, I will add an icon. For the center and right alignment, use the left and right attributes for the ul element to be located. Check the final Demo effect:

@media screen and (max-width: 600px) {    .nav {        position: relative;        min-height: 40px;    }        .nav ul {        width: 180px;        padding: 5px 0;        position: absolute;        top: 0;        left: 0;        border: solid 1px #aaa;        background: #fff url(images/icon-menu.png) no-repeat 10px 11px;        border-radius: 5px;        box-shadow: 0 1px 2px rgba(0,0,0,.3);    }    .nav li {        display: none; /* hide all <li> items */        margin: 0;    }    .nav .current {        display: block; /* show only current <li> item */    }    .nav a {        display: block;        padding: 5px 5px 5px 32px;        text-align: left;    }    .nav .current a {        background: none;        color: #666;    }    /* on nav hover */    .nav ul:hover {        background-image: none;    }    .nav ul:hover li {        display: block;        margin: 0 0 5px;    }    .nav ul:hover .current {        background: url(images/icon-check.png) no-repeat 10px 7px;    }    /* right nav */    .nav.right ul {        left: auto;        right: 0;    }    /* center nav */    .nav.center ul {        left: 50%;        margin-left: -90px;    }    }

Related blog recommendations:

10 Responsive design navigation Menu source code: http://www.shejidaren.com/10-responsive-navigation-tutorials.htmlCreating a CSS3 Responsive Menu: Success/

Demo: http://red-team-design.com/wp-content/uploads/2013/02/animenu-demo.html


First: http://www.ido321.com/1386.html


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.