I'm trying to create a responsive navbar, but not all the items from my ul are showing,
PROBLEM:
console.log('works')
document.querySelector('.container__hamburger').addEventListener('click', ()=>{
document.querySelector('.container__navbar').classList.toggle('showMenu')
})
@import url("https://fonts.googleapis.com/css2?family=Roboto&display=swap");
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
.container {
display: flex;
background-color: #2b2f33;
width: 100%;
height: 65px;
}
.container__navbar {
display: flex;
font-family: "Roboto", sans-serif;
width: 100%;
}
.container__logo {
display: inline;
width: 25%;
margin-right: 30px;
margin-left: 10px;
}
.navbar__list {
display: flex;
width: 100%;
list-style: none;
align-items: center;
color: #ffffff;
}
.list__item{
margin-right: 30px;
}
.container__hamburger {
display: none;
color: #ffffff;
align-self: center;
}
@media (max-width: 890px) {
.container {
position: fixed;
}
.container__navbar {
position: fixed;
height: 100%;
left: 0;
top: 65px;
transition: 0.5s;
background-color: #2b2f33;
transform: translateX(-100%);
width: 250px;
}
.showMenu {
transform: translateX(0);
}
.navbar__list {
display: block;
overflow-x: hidden;
overflow-y: scroll;
}
.container__hamburger {
display: block;
margin-left: auto;
margin-right: 30px;
}
.list__item {
width: 100%;
padding: 10px;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<div class="container">
<img
class="container__logo"
src="assets/images/gamezonia.png"
alt="logo"
/>
<nav class="container__navbar">
<ul class="navbar__list">
<li class="list__item">Home</li>
<li class="list__item">Category 1</li>
<li class="list__item">Category 2</li>
<li class="list__item">Category 3</li>
<li class="list__item">Contact</li>
<li class="list__item">Item</li>
<li class="list__item">Item2</li>
<li class="list__item">Item3</li>
<li class="list__item">Item4</li>
<li class="list__item">Item5</li>
<li class="list__item">Item6</li>
</ul>
</nav>
<div class="container__hamburger">
<i class="fas fa-bars"></i>
</div>
</div>
<!-- FONT AWESOME -->
<script
src="https://kit.fontawesome.com/96fadf0e69.js"
crossorigin="anonymous"
></script>
<!-- FONT AWESOME -->
<script src="./index.js"></script>
</body>
</html>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…