A Pen by Ariel Balter on CodePen.
Created
April 5, 2018 03:55
-
-
Save abalter/f84c89a1a5fcaa33c9d07074adb1943e to your computer and use it in GitHub Desktop.
Super simple flexbox responsive nav
This file contains hidden or 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
<div id="nav"> | |
<div id="menu-toggle"><button id="hamburger">MENU</button></div> | |
<div class="nav-items"> | |
<a href="#home" class="active">Home</a> | |
<a href="#news">News</a> | |
<a href="#contact">Contact</a> | |
<a href="#about">About</a> | |
</div> | |
</div> |
This file contains hidden or 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
$('#menu-toggle').on('click', (e) => | |
{ | |
console.log("menu-toggle"); | |
toggleCSS('.nav-items', 'display', 'block', 'none'); | |
}); | |
$('.nav-items a').on('click', (e) => | |
{ | |
toggleCSS('.nav-items', 'display', 'block', 'none'); | |
}); | |
function toggleCSS(element, attribute, state1, state2) | |
{ | |
console.log(`element: ${element} attribute: ${attribute} state1: {state1} state2: ${state2}`); | |
console.log($(element).css(attribute)); | |
$(element).css(attribute) == state1 ? $(element).css(attribute, state2) : $(element).css(attribute, state1); | |
return $(element); | |
} | |
$(window).resize(() => {location = location; console.log($('.nav-items').css('display'))}); |
This file contains hidden or 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
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script> |
This file contains hidden or 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
body { | |
font-family: Arial, Helvetica, sans-serif; | |
} | |
#nav { | |
} | |
.nav-items { | |
width: 100%; | |
display: block; | |
} | |
.nav-items a { | |
text-align: center; | |
display: inline-block; | |
} | |
.nav-items a:hover { | |
color: red; | |
} | |
#menu-toggle { | |
display: none; | |
margin: 0 auto; | |
} | |
@media screen and (max-width: 600px) { | |
#nav { | |
text-align: center; | |
} | |
.nav-items { | |
display: none; | |
margin: 1rem auto; | |
} | |
.nav-items a { | |
display: block; | |
} | |
#menu-toggle { | |
display: block; | |
} | |
} | |
@media screen and (min-width: 601px) { | |
.nav-items { | |
display: inline-block; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment