How CSS and JS implement responsive navigation menus

Source: Internet
Author: User
This article is about how CSS and JS can implement the responsive navigation menu, the content is very valuable, and I hope to help the small partners in need.

1. Responsive navigation Menu

When the viewport is larger than 640px, the navigation bar will appear outside, and when the viewport is less than 768px, the navigation menu needs to be hidden!
The code is as follows:

<!doctype html>

The

CSS code is as follows:

body{margin:0;}.    nav{Background-color:black;    width:100%; Position:relative;}.    Nav ul{margin:0;    padding:0;    width:80%; margin:0 Auto;}.    clearfix:after{Display:block;    Content: "";    height:0;    Clear:both; Visibility:hidden;}.    Nav ul li{List-style:none; Float:left;}.    Nav ul Li a{color:white;    padding:20px 30px;    Display:block; Text-decoration:none;}. Nav ul Li a:hover{background-color:red;}.    pic{Background:url (logo.jpg) no-repeat;    Position:absolute;    top:5px;    left:5px;    width:113px; height:39px;}.    btn{Background-color: #333;    Text-align:right;    Color:white;    font-size:20px;    padding:10px; Display:none;}        @media screen and (max-width:640px) {. Nav ul li{Float:none;    Text-align:center;    }. Nav ul{width:100%;    }. btn{Display:block;        }. pic{Position:absolute;        left:50%;    margin-left:-56px; }}
Related Article

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.