In the current scenario, the menu is expanded in desktop view and hidden in mobile view.
My query is how can we achieve the following:
- For mobile view: do not hide, expand the menu
- For desktop view: hide the menu
$('#nav-toggle').click(function() {
$('nav').toggleClass("active");
});
* {
margin: 0;
padding: 0;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
html,
body {
font-family: sans-serif;
font-size: 100%;
}
#top-bar {
position: relative;
max-width: 1000px;
height: 85px;
background-color: #22bbff;
margin-left: auto;
margin-right: auto;
}
#nav-toggle {
float: right;
display: block;
border-left: 1px solid #fff;
}
nav {
float: right;
}
.active ul {
display: block;
}
ul {
position: absolute;
display: none;
top: 60px;
right: 0;
width: 150px;
list-style-type: none;
background-color: #22bbff;
border: 1px solid #fff;
text-align: center;
}
li {
display: block;
}
a {
display: block;
padding-top: 21px;
padding-right: 40px;
padding-left: 40px;
padding-bottom: 21px;
color: #fff;
text-decoration: none;
background-color: #294C52;
border: 1px solid #fff;
}
a:hover {
background-color: #1BBC9B;
border: 1px solid #fff;
}
@media screen and (min-width: 767px) {
nav {
position: relative;
float: right;
right: 50%;
}
#nav-toggle {
display: none;
}
ul {
position: relative;
float: right;
display: block;
top: 0;
right: -50%;
width: auto;
height: 60px;
list-style-type: none;
border: none;
}
li {
float: left;
display: block;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<div id="top-bar">
<a href="#" id="nav-toggle">M</a>
<nav>
<ul>
<li><a href="#">Link 1</a>
</li>
<li>
<a href="#">Link 2 <i></i></a>
</li>
<li><a href="#">Link 3</a>
</li>
</ul>
</nav>
</div>