I'm fairly new to HTML and CSS and I've put together a navigation bar. The purpose of the navigation bar is to be clean and mobile-friendly. I would appreciate some feedback on what I could do better within the code as I don't know what's best just yet.
const navSlide = () => {
const burger = document.querySelector('.burger');
const nav = document.querySelector('.nav-links');
const navLinks = document.querySelectorAll('.nav-links li');
//togle nav
burger.addEventListener('click', () => {
nav.classList.toggle('nav-active');
navLinks.forEach((link, index) => {
if (link.style.animation) {
link.style.animation = '';
} else {
link.style.animation = `navLinkFade 0.5s ease forwards ${index / 7 + .3}s`;
}
});
burger.classList.toggle('toggle');
});
}
navSlide();
@import url('https://fonts.googleapis.com/css?family=Montserrat:400,500,700&display=swap');
@import url('https://fonts.googleapis.com/css?family=Fira+Sans:400,400i,500,500i,700,700i&display=swap');
* {
margin: 0;
padding: 0;
}
body {
background-color: #E5ECE9;
height: 2000px;
font-family: 'montserrat', sans-serif;
}
nav {
display: flex;
justify-content: space-between;
align-items: center;
min-height: 8vh;
background-color: white;
flex-basis: 1336px;
padding-left: 10%;
padding-right: 10%;
}
.logo img {
height: 84px;
max-width: 100%;
}
.nav-links {
display: flex;
justify-content: space-around;
}
.nav-links li {
list-style-type: none;
padding: 10px 10px 10px;
}
.nav-links a {
color: black;
text-decoration: none;
letter-spacing: 2px;
font-weight: 500;
font-family: 'montserrat', sans-serif;
font-size: 14px;
}
.nav-links #green-select {
font-weight: bold;
color: #A7E66E;
}
.burger {
display: none;
cursor: pointer;
}
.burger div {
width: 25px;
height: 3px;
background-color: black;
margin: 3px;
transition: all 0.3s ease;
}
.landing-wrapper {
width: 100%;
background-color: white;
height: 694px;
}
.landing {
width: 1336px;
position: absolute;
top: 40%;
left: 50%;
transform: translate(-50%, -50%);
}
.landing h1 {
text-align: center;
font-size: 70px;
font-family: 'Fira Sans', sans-serif;
font-style: italic;
line-height: 90%;
padding-bottom: 20px;
}
.landing p {
text-align: center;
font-size: 18px;
font-family: 'montserrat', sans-serif;
padding-left: 15%;
padding-right: 15%;
line-height: 1.6;
}
/* Responsive Design */
@media screen and (max-width: 1024px) {}
@media screen and (max-width:768px) {
body {
overflow-x: hidden;
}
.nav-links {
position: absolute;
right: 0px;
height: 92vh;
top: 9vh;
background-color: white;
display: flex;
flex-direction: column;
align-items: center;
width: 100%;
transform: translateX(100%);
transition: transform 0.5s ease-in;
}
.nav-links li {
opacity: 0;
}
.burger {
display: block;
}
}
.nav-active {
transform: translateX(0%);
}
@keyframes navLinkFade {
from {
opacity: 0;
transform: translateX(50px);
}
to {
opacity: 1;
transform: translateX(0px);
}
}
.toggle .line1 {
transform: rotate(-45deg) translate(-5px, 6px);
}
.toggle .line2 {
opacity: 0;
}
.toggle .line3 {
transform: rotate(45deg) translate(-5px, -6px);
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="style.css">
<meta http-equiv="Cache-control" content="no-cache">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Navigation Tutorial</title>
</head>
<body>
<nav>
<div class="logo">
<img src="logo.png">
</div>
<ul class="nav-links">
<li><a id="green-select" href="#">Showcase</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Blog</a></li>
<li><a href="#">Contact</a></li>
</ul>
<div class="burger">
<div class="line1"></div>
<div class="line2"></div>
<div class="line3"></div>
</div>
</nav>
<script src="app.js"></script>
</body>
</html>