I'm a beginner Web Developer who is currently working on my first responsive website. I’ve run into an issue with my dropdown menu where the width (which I want to cover the whole screen) begins to reduce when the screen size passes a certain threshold (484 pixels or less). I had a similar issue in other areas of my site that after some research I was able to fix by adding “mid-width: fit-content;” to my HTML ruleset, but it doesn’t seem to be helping the dropdown. Any idea what could be causing this? I’ve been unable to find a cause or solution so any advice would be greatly appreciated.
Below is a simplified version of my code:
<!DOCTYPE html>
<html lang = "en">
<head>
<meta charset="UTF-8">
<title>A Website</title>
<link rel="stylesheet" href="./styles/MenuTestCSS.css">
<meta name="viewport" content="width=device-width">
</head>
<body>
<header>
<div class="flexContainer">
<div id="logoBox">
<h2 id="logo">Website</h2>
</div>
<nav>
<ul id="menu" class="flexContainer">
<li class = "navLink"><a href="" >Link</a></li>
<li class = "navLink"><a href="">Link</a></li>
<li class = "navLink"><a href="">Link</a></li>
<li class = "navLink"><a href="">Link</a></li>
</ul>
<div class="flexContainer">
<div id="menuToggle">
<div class="square"></div>
<div class="square"></div>
<div class="square"></div>
</div>
</div>
</nav>
</div>
</header>
</body>
</html>
/* GENERAL STYLES */
html {
box-sizing: border-box;
min-width: fit-content;
}
body {
width: 100%;
}
*, *::before, *::after {
box-sizing: inherit;
margin: 0;
padding: 0;
}
.flexContainer{
display: flex;
flex-flow: row wrap;
}
/* HEADER STYLES */
header {
color: white;
background-color: #485696;
height: auto;
}
header .flexContainer {
align-items: center;
height: 100%;
width: 100%;
}
header h2 {
font-size: 48px;
margin: 20px 0;
padding-left: 25px;
}
nav {
align-self: stretch;
width: 485px;
}
nav .flexContainer {
justify-content: space-around;
}
header a, header a:visited {
color: white;
text-decoration: none;
font-size: 26px;
}
header li {
display: inline-block;
}
#menuToggle {
width: 45px;
height: 50px;
display: none;
}
.square{
width: 45px;
background-color: white;
height: 5px;
}
.square .square {
margin-top: 10px;
}
nav {
flex: 1 0 0;
}
nav .flexContainer {
justify-content: flex-end;
}
#menuToggle {
margin-right: 3em;
width: 30px;
height: 30px;
display: block;
}
#menu {
background-color:#485696;
position: absolute;
top: 92px;
left: 0%;
height: auto;
padding: 10px 25px;
display: block;
border-top: 4px solid white;
}
.navLink .navLink {
margin-top: 1em;
}
#menu li {
display: block;
}
.navLink .navLink {
margin-left: 0px;
}
CodePudding user response:
You've got this issue because you set nav{ width: 485px }
so it's logically will be shrinked when the with is lower than 485px, I notice you to learn about relative lengths such as "%", "rem", "em", "vh"...
so in your case you'll just change the nav { width: 485px }
by width: 100%