JSFiddle - React, Tailwind, and code Playground
by Spencer Smith
HTML
<div class="content">
<h1>Page Title</h1>
<p>This is the main page</p>
<p>The second paragraph is the best</p>
</div>
<div id="menu-overlay" class="hidden">
<div id="menu">
<a href="">Audio</a>
<a href="">Poems</a>
<a href="">Photos</a>
<a href="">Resume</a>
</div>
</div>
<div class="menu-button">☰</div>
CSS
body {
font-family: sans-serif;
background-color: white;
}
#menu-overlay {
position: fixed;
top: 0; right: 0; left: 0; bottom: 0;
background-color: #333;
padding: 30px;
}
.menu-button {
width: 35px;
height: 35px;
background-color: #333;
border-radius: 100px;
color: white;
font-size: 35px;
text-align: center;
line-height: 35px;
padding: 5px;
cursor: pointer;
position: absolute;
top: 20px; left: 20px;
box-shadow: 0 0 0 2px transparent;
user-select: none;
transition: box-shadow .2s;
}
.menu-button:hover {
box-shadow: 0 0 0 2px white;
}
#menu {
float: left;
margin-top: 20vh;
}
#menu a {
float: left;
clear: both;
color: white;
text-decoration: none;
font-size: 1.6rem;
margin: 6px 0;
padding-left: 4px;
font-weight: 200;
border-left: 2px solid transparent;
transition: all .2s;
}
#menu a:hover {
border-left: 2px solid white;
padding-left: 10px;
}
.ex {
font-weight: 100;
line-height: 32px;
}
.content {
width: 400px;
margin: 0 auto;
}
.hidden {
display: none;
}
JavaScript
var menuButton = document.querySelector('.menu-button');
var overlay = document.querySelector('#menu-overlay');
menuButton.addEventListener('click', menuButtonClicked);
function menuButtonClicked(){
if(overlay.classList.contains('hidden')){
// Menu visible
this.innerHTML = '×';
this.classList.add('ex');
overlay.classList.remove('hidden');
} else {
// Menu hidden
this.innerHTML = '☰';
this.classList.remove('ex');
overlay.classList.add('hidden');
}
}