I have a nav bar which takes up all the width on desktop, but on mobile it doesn’t
HTML:
<ul>
<li><#">Home</a></li>
<li><#">Dev Log</a></li>
<li><#">Credits</a></li>
</ul>
</nav>
CSS:
* {
box-sizing: border-box;
}
body, html {
margin: 0 auto;
padding: 0;
}
body {
margin: 0;
font-family: Arial, Helvetica, sans-serif;
background-color: #7AE7C7;
text-align: center;
}
nav{
background-color: #0b4e2d;
font-size:18px;
padding:6px;
margin: 0;
width: 100vw;
}
ul {
list-style: none;
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 10px;
position: relative;
color: white;
margin-left: 15px;
padding: 0;
font-family: Arial, Helvetica, sans-serif;
}
ul a {
color: white;
text-decoration: none;
}
ul a:hover {
text-decoration: underline;
}
I tried using 100% width and 100% vw on the nav and ul but it didn’t work. It seems to only happen when an element is under it
2
Answers
The problem with your CSS is that you are setting the width of the nav element to 100vw. This means that it will be the full width of the viewport, regardless of the device. However, on mobile devices, the viewport is often smaller than the screen. This is because the viewport includes the address bar and other UI elements.
To fix this, you need to set the width of the nav element to 100% instead of 100vw. This will make it the full width of the screen, even on mobile devices.
I can’t find anything wrong, but I have cleaned it up a bit.