I'm doing a single-page website where there are anchor points and so on that when selecting a menu option, go down to where the content is (until then everything is fine) but the menu does not close and does not let me see the information.
I hope you can help me please!
$(document).ready(function(){
$('.menu-toggle').click(function(){
$('nav').toggleClass('active')
})
})
body
{
margin: 0;
padding: 0;
font-family: sans-serif;
background-attachment: fixed;
background-position: center;
}
header
{
position: fixed; /*probar con fixed para que quede el menu fijo*/
top: 0;/**/
left: 0;/**/
padding: 0 100px;/**/
background: #262626; /*rgba(0,0,0,.8)*/
width: 100%;
box-sizing: border-box;/**/
z-index: 1000; /*complemento para que quede fijo el menu*/
}
header .logo
{
color: #fff;
height: 50px;
line-height: 50px;
font-size: 24px;
float: left;
font-weight: bold;
}
header nav
{
float: right;
}
header nav ul /*dar un tamaño optimo a la barra del menu*/
{
margin: 0;
padding: 0;
display: flex;
}
header nav ul li
{
list-style: none;
}
header nav ul li a
{
height: 50px;
line-height: 50px;
padding: 0 20px;
color: #fff;
text-decoration: none;
display: block;
}
header nav ul li a:hover,
header nav ul li a.active
{
color: #fff;
background: #2196f3;
}
.menu-toggle
{
color: #fff;
float: right;
line-height: 50px;
font-size: 24px;
cursor: pointer;
display: none;
}
@media (max-width: 991px) /*para que quede a la par el logo y el menu cuando se haga pequeña la pagina*/
{
header
{
padding: 0 20px;
}
.menu-toggle
{
display: block;
}
header nav
{
/*display: none;*/
position: absolute;
width: 100%;
height: calc(100vh - 50px); /*quita el scroll del lado derecho*/
background: #333;
top: 50px;
left: -100%;
transition: 0.5s;
}
header nav.active
{
left: 0;
}
header nav ul
{
display: block;
text-align: center; /*centra el menu responsivo*/
}
header nav ul li a
{
border-bottom: 1px solid rgba(0,0,0,.2);
}
}
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<header>
<div class="logo">MIXOTE</div>
<nav>
<ul>
<li><a href="#" class="active">Inicio</a></li>
<li><a href="#">Nosotros</a></li>
<li><a href="#service">Servicios</a></li>
<li><a data-scroll href="#contacto">Contacto</a></li>
</ul>
</nav>
<div class="menu-toggle"><i class="fa fa-bars" aria-hidden="true"></i></div>
</header>