r/CodingForBeginners • u/eveveveee • 31m ago
How do I do a mobile menu that you can toggle with CSS?
I'm trying to get my website to work for mobile and the navigation is really not working for me. The bar on top doesn't look nice on the small screen, so I've been trying to make a navigation icon that you can toggle to bring up a side menu. I found a method for it with CSS (the checkbox method https://css-tricks.com/the-checkbox-hack/ ) but I can't get it to work for me! Does anyone know what I'm doing wrong?
This is my default CSS
#nav-box{
width:100vw;
height: 50px;
background-color:#282147;/*darker purple*/
margin-top:-75px;
margin-left:-10px;
padding:5px 0;
position:fixed;
font-size:20px;
z-index:1000;
}
#nav-box ul{
float:right;
}
#nav-box li{
margin-top:-15px;
}
#nav-box a{
color:#fbfcde;
text-decoration:none;
}This is my CSS in a media query (the problem zone)
#nav-box{
font-size:1.5em;
position:fixed;
margin:0;
white-space: nowrap;
height:60px;
}
#mobile-nav{
background:url(https://itsaneve.neocities.org/Portfolio/imgs/burger%20menu.png);
background-size:contain;
width:35px;
height:40px;
float:right;
padding:10px;
margin-right:10px;
z-index:1000;
padding:5px;
}
#nav-list{
opacity:0.0;
width:50vw;
height:100vh;
position:relative;
background-color:#282147;
overflow:visible;
top:40px;
right:-50px;
padding:5px;
}
#nav-check:checked ~ #nav-list{
opacity:1.0;
}This is my html
<header>
<section id="nav-box">
<nav> <label for="nav-check" id="mobile-nav"><input type="checkbox" id="nav-check"></label>
<ul id="nav-list">
<li class="current">Home</li>
<li><a href="wip.html" id="wip-pg-nav">Escape!</a></li>
<li> <a href="index.html">Animation</a></li>
<li> <a href="illu.html">Still Art</a></li>
<li> <a href="boardin.html">Storyboards</a></li>
<li><a href="abt.html">About Me</a></li>
</ul>
</nav>
</section>
</header>
