Responsive Menu


desktop view
desktop view

HTML5 CODE

<nav class=”nav center”>
<ul>
<li class=”current”><a href=”#”>Link 1</a></li>
<li><a href=”#”>Link 2</a></li>
<li><a href=”#”>Link 3</a></li>
<li><a href=”#”>Link 4</a></li>
<li><a href=”#”>Link 5</a></li>
</ul>
</nav>

 

CSS3 CODE

.nav {
position: relative;
margin: 20px 0;

}
.nav ul {
background-color:#0CF;
margin: 0;
padding: 25px;

}
.nav li {
margin: 0 5px 10px 0;
padding: 0;
list-style: none;
display: inline-block;
}
.nav a {
font-family:Arial, Helvetica, sans-serif;
padding: 3px 15px;
text-decoration: none;
color: #FFF;
line-height: 100%;
}
.nav a:hover {
color: #000;
}
.nav .current a {
background: #FFF;
color: #0CF;
border-radius: 5px;
}
.nav.center ul {
text-align: center;
}

Just adding the above code does not enable Responsive Behabiour

in order to make it resposive we have to add the @media screen propertiry

 

What @media screen really does?

here inside the @media-screen the : max-width property determine the screen size if it is less then 600px the code written inside the 

@media screen and (max-width: 600px) {

}

will be executed automatically for the browser..

 

@media screen and (max-width: 600px) {
.nav {
position: relative;
min-height: 40px;
}
.nav ul {
background-color:#0CF;
padding: 25px;
width: 180px;
padding: 5px 0;
position: absolute;
top: 0;
left: 0;
border: solid 1px #aaa;
background:url(rwd-menu-icons.png) no-repeat;
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 45px;
text-align: left;
color:#000;
}
.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;
background-size:10% 8%;
}

.nav.center ul {
left: 50%;
margin-left: -90px;
}

}

mobile view
mobile view

 

 

Want to say something....