Instantly share code, notes, and snippets.
Last active
April 7, 2021 17:39
-
Star
0
(0)
You must be signed in to star a gist -
Fork
0
(0)
You must be signed in to fork a gist
-
Save HarryAdney/07d2907538bd81c32a04af88f0b6d658 to your computer and use it in GitHub Desktop.
Accessible navigation using Flexbox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Flexbox nav</title> | |
<style> | |
* { | |
box-sizing: border-box; | |
padding: 0; | |
margin: 0; | |
} | |
body { | |
font-family: 'Josefin Sans', sans-serif; | |
} | |
.navbar { | |
font-size: 18px; | |
background-image: linear-gradient(260deg, #2376ae 0%, #c16ecf 100%); | |
border: 1px solid rgba(0, 0, 0, 0.2); | |
padding-bottom: 10px; | |
} | |
.main-nav { | |
list-style-type: none; | |
display: none; | |
} | |
.nav-links, | |
.logo { | |
text-decoration: none; | |
color: rgba(255, 255, 255, 0.7); | |
} | |
.main-nav li { | |
text-align: center; | |
margin: 15px auto; | |
} | |
.logo { | |
display: inline-block; | |
font-size: 22px; | |
margin-top: 10px; | |
margin-left: 20px; | |
} | |
.navbar-toggle { | |
position: absolute; | |
top: 10px; | |
right: 20px; | |
cursor: pointer; | |
/* color: rgba(255, 255, 255, 0.8); */ | |
font-size: 1.2rem; | |
background-color: aqua; | |
border-radius:5px | |
} | |
.skip-link { | |
/* background: #319795; */ | |
color: #fff; | |
font-weight: 700; | |
left: 30%; | |
padding: 4px; | |
position: absolute; | |
transform: translateY(-100%); | |
transition: transform 0.3s; | |
} | |
.skip-link:focus { | |
transform: translateY(0%); | |
} | |
.active { | |
display: block; | |
} | |
@media screen and (min-width: 768px) { | |
.navbar { | |
display: flex; | |
justify-content: space-between; | |
padding-bottom: 0; | |
height: 70px; | |
align-items: center; | |
} | |
.main-nav { | |
display: flex; | |
margin-right: 30px; | |
flex-direction: row; | |
justify-content: flex-end; | |
} | |
.main-nav li { | |
margin: 0; | |
} | |
.nav-links { | |
margin-left: 40px; | |
} | |
.logo { | |
margin-top: 0; | |
} | |
.navbar-toggle { | |
display: none; | |
} | |
.logo:hover, | |
.nav-links:hover { | |
color: rgba(255, 255, 255, 1); | |
} | |
} | |
</style> | |
<script src="https://kit.fontawesome.com/22c474940b.js" crossorigin="anonymous"></script> | |
</head> | |
<body> | |
<header> | |
<a class="skip-link" href="#main">Skip to main content</a> | |
<nav class="navbar"> | |
<button class="navbar-toggle" id="js-navbar-toggle"> | |
<i class="fas fa-bars"> Menu</i> | |
</button> | |
<a href="#" class="logo">logo</a> | |
<ul class="main-nav" id="js-menu"> | |
<li> | |
<a href="#" class="nav-links">Home</a> | |
</li> | |
<li> | |
<a href="#" class="nav-links">Lesons</a> | |
</li> | |
<li> | |
<a href="#" class="nav-links">About Us</a> | |
</li> | |
<li> | |
<a href="#" class="nav-links">Contact Us</a> | |
</li> | |
<li> | |
<a href="#" class="nav-links">Blog</a> | |
</li> | |
</ul> | |
</nav> | |
</header> | |
<main> | |
Main Content | |
</main> | |
<footer> | |
Footer | |
</footer> | |
<script> | |
let mainNav = document.getElementById('js-menu'); | |
let navBarToggle = document.getElementById('js-navbar-toggle'); | |
navBarToggle.addEventListener('click', function () { | |
mainNav.classList.toggle('active'); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment