JSFiddle - React, Tailwind, and code Playground
by seanmcdon
HTML
<body>
<header>
<div class="nav">
<ul>
<li class="home"><a href="#one">Home</a></li>
<li class="tutorials"><a class="active" href="#two">
Tutorials</a></li>
<li class="about"><a href="#three">About</a></li>
<li class="news"><a href="#four">Newsletter</a></li>
<li class="contact"><a href="#five">Contact</a></li>
</ul>
</div>
</header>
<div class="page" id="one">
Content of page 1 goes here.
</div>
<div class="page" id="two">
Content of page 2 goes here.
</div>
<div class="page" id="three">
Content of page 2 goes here.
</div>
<div class="page" id="four">
Content of page 2 goes here.
</div>
<div class="page" id="five">
Content of page 2 goes here.
</div>
</body>
CSS
body {
margin: 0;
padding: 0;
background: #ccc;
}
.nav ul {
list-style: none;
background-color: #444;
text-align: center;
padding: 0;
margin: 0;
}
.nav li {
font-family: 'Oswald', sans-serif;
line-height: 1em;
height: 1em;
border-bottom: 1px solid #888;
}
.nav a {
text-decoration: none;
color: #fff;
display: block;
transition: .3s background-color;
}
.nav a:hover {
background-color: #005f5f;
}
.nav a.active {
background-color: #fff;
color: #444;
cursor: default;
}
@media screen and (min-width: 600px) {
.nav li {
width: 10vw;
border-bottom: none;
height: 10vh;
margin-left: 2vw;
margin-right: 2vw;
}
/* Option 1 - Display Inline */
.nav li {
display: inline-block;
}
/* Options 2 - Float
.nav li {
float: left;
}
.nav ul {
overflow: auto;
width: 600px;
margin: 0 auto;
}
.nav {
background-color: #444;
}
*/
}
.page {
width: 100vw;
height: 100vh;
position: fixed;
top: calc(30vh+5px);
left: -100vw;
overflow-y: auto;
z-index: 0;
background-color: hsl(0,0%,100%);
padding: 0em;
}
.page:target {
left: 0vw;
z-index: 1;
animation: .5s leftright;
}
@keyframes leftright {
0%{ left: -100vw; }
100%{ left: 0vw; }
}
}
JavaScript
Array.from(document.querySelectorAll("a"))
.map(x => x.addEventListener("click",
function(e){
Array.from(document.querySelectorAll("a"))
.map(x => x.classList.remove("active"));
e.target.classList.add("active");
}
));