I'm having trouble with positioning an icon using margin-top: -35px; under #menu. When I click on the icon, the side navigation bar doesn't work properly. However, if I adjust it to -15px, the side navigation bar displays correctly. Can someone help me figure out what I'm doing wrong?
Thank you in advance!
https://i.sstatic.net/5tnWT.png
function openNav() {
document.getElementById("mySidenav").style.width = "250px";
}
function closeNav() {
document.getElementById("mySidenav").style.width = "0";
}
#menu{
float: right;
margin-top: -15px;
}
.sidenav {
height: 100%;
width: 0;
position: fixed;
z-index: 1;
top: 0;
right: 0;
opacity: 0.5;
background-color: #ffffff;
overflow-x: hidden;
transition: 0.5s;
padding-top: 90px;
}
.sidenav a {
padding: 8px 8px 8px 32px;
text-decoration: none;
font-size: 25px;
color: black;
display: block;
transition: 0.3s
}
.sidenav a:hover, .offcanvas a:focus{
color: #808080;
}
.sidenav .closebtn {
position: absolute;
top: 0;
right: 25px;
font-size: 36px;
margin-left: 50px;
}
@media screen and (max-height: 450px) {
.sidenav {padding-top: 15px;}
.sidenav a {font-size: 18px;}
}
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<span style="font-size:30px;cursor:pointer" onclick="openNav()"><i class="material-icons material-spec-icon" title="Show navigation">menu</i></span>
<div id="mySidenav" class="sidenav">
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">×</a>
<a href="#">About</a>
<a href="#">Services</a>
<a href="#">Process</a>
<a href="#">Portfolio</a>
</div>