My navigation won't show properly when I make the viewport smaller. When I refresh the page, it works. However if I make it big again, my navigation is gone. What am I missing? I tried writing the code another way but I'm not experienced enough.
I would like it to directly show it how it's supposed to be, not that I have to refresh the page when I resize my viewport.
$(document).ready(function() {
if ($(window).width() < 800) {
$('.dropdown').hide();
$('.fa-bars').click(function() {
$("ul").toggleClass("toggled");
$('.dropdown').slideToggle();
})
}
})
@media screen and (max-width: 800px) {
header {
position: fixed;
z-index: 1;
height: auto;
width: 35vw;
}
nav ul {
flex-direction: column;
border-radius: 0 0 20px 0;
width: 230px;
padding-bottom: 10px;
margin-left: 70px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<header>
<nav>
<ul>
<li id="mobileDropdown">
<a href="index.html" title="Home"><img id="Logo" src="../Images/Logo.svg"></a>
<i class="fas fa-bars"></i>
</li>
<li class="rectangle dropdown"><a href="ueber_mich.html">Über mich</a></li>
<li class="rectangle dropdown"><a href="aktuell.html">Aktuell</a></li>
<li id="AktuelleSeite" class="dropdown"><a href="portfolio.html">Portfolio</a></li>
<li class="rectangle dropdown"><a href="angebot.html">Angebot</a></li>
<li class="rectangle dropdown"><a href="kontakt.html">Kontakt</a></li>
</ul>
</nav>
</header>