Frage zu Responsive Nav, Burger Button?
Hi, also ich verstehe hier folgendes nicht :
Warum das Hamburger Symbol bei bei zutreffender Mediaquerry "@media (max-width: 768px)", angezeigt wird, denn schließlich ist doch der ".menu-toggle" auf "display: none;" ???
Eventuell verstehe ich es richtig, dass durch ".classList.toggle('nav-active');" in der "function toggleMenu()" irgendwie der Burger aktiviert wird, durch eine versteckte VanillaJS Funktion, aber wie genau?
Danke
LG
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Meine Website</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: Arial, sans-serif;
}
body {
display: flex;
flex-direction: column;
align-items: center;
}
.navbar {
width: 100%;
background-color: #333;
display: flex;
justify-content: space-between;
align-items: center;
padding: 15px;
}
.logo {
color: white;
font-size: 24px;
font-weight: bold;
}
.nav-links {
list-style: none;
display: flex;
}
.nav-links li {
margin: 0 15px;
}
.nav-links a {
color: white;
text-decoration: none;
font-size: 18px;
}
.menu-toggle {
display: none;
font-size: 24px;
color: white;
cursor: pointer;
}
@media (max-width: 768px) {
.nav-links {
display: none;
flex-direction: column;
background-color: #333;
position: absolute;
top: 60px;
right: 0;
width: 100%;
text-align: center;
}
.nav-links li {
padding: 10px 0;
}
.menu-toggle {
display: block;
}
.nav-active {
display: flex;
}
}
</style>
</head>
<body>
<nav class="navbar">
<div class="logo">Mein Logo</div>
<span class="menu-toggle" onclick="toggleMenu()">☰</span>
<ul class="nav-links">
<li><a href="#">Home</a></li>
<li><a href="#">Über</a></li>
<li><a href="#">Leistungen</a></li>
<li><a href="#">Kontakt</a></li>
</ul>
</nav>
<script>
function toggleMenu() {
document.querySelector('.nav-links').classList.toggle('nav-active');
}
</script>
</body>
</html>
ps:Ok hat sich geklärt...ich depp habe übersehen das die unteren css eigenschaften ja in der Mediaquerry drinne sind