Simple Collapsable Navbar
How do I make an simple collapsable navbar?
Collapsable navbar templates such as Bootstrap exist but often include a lot of extra stuff that you have to remove if you just want something simpler. This is that something simpler. I wanted to build something extremely simple and easy to modify so that it can be used anything that just requires a simple navbar that collapses for a mobile screen.. What is a simple collapsable navbar? How do you make a simple collapsable navbar? This script and codes were developed by Dan on 07 January 2023, Saturday.
Simple Collapsable Navbar - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Simple Collapsable Navbar</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <link rel="stylesheet" href="css/style.css">
</head>
<body> <nav> <div class="navWide"> <div class="wideDiv"> <a href="#">Link 1</a> <a href="#">Link 2</a> <a href="#">Link 3</a> </div> </div> <div class="navNarrow"> <i class="fa fa-bars fa-2x"></i> <div class="narrowLinks hidden"> <a href="#">Link 1</a> <a href="#">Link 2</a> <a href="#">Link 3</a> </div> </div>
</nav> <script src="js/index.js"></script>
</body>
</html>
Simple Collapsable Navbar - Script Codes CSS Codes
nav { background-color: #CCC; overflow: hidden; padding: 1em; border-bottom: 1px solid #000;
}
nav a { color: #000;
}
nav a:visited { color: #000;
}
nav .navWide { display: none; margin: 0 auto;
}
nav .navWide .wideDiv { text-align: center;
}
nav .navWide .wideDiv a { text-decoration: none; display: inline-block; /*Adjust padding to increase/decrease the space between links.*/ padding: 0 2em;
}
/*Navbar is set to default with the "hamburger" and links on the left
side of the screen. To move to the right of the screen, simply
change the three "float: Left;" references to read "float: right;".*/
nav .navNarrow i { float: left; cursor: pointer; color: #000;
}
nav .navNarrow .narrowLinks a { text-decoration: none; display: block; float: left; clear: left; padding: 0.5em 0;
}
.hidden { display: none;
}
/*Adjust breakpoint as desired to select when the "hamburger" menu is
replaced by just the links.*/
@media (min-width: 480px) { nav .navWide { display: block; } nav .navNarrow { display: none; }
}
Simple Collapsable Navbar - Script Codes JS Codes
'use strict';
var navLinks = document.querySelector('.navNarrow');
var narrowLinks = document.querySelector('.narrowLinks');
navLinks.addEventListener('click', toggle);
function toggle() { narrowLinks.classList.toggle('hidden');
};
Developer | Dan |
Username | danbuda |
Uploaded | January 07, 2023 |
Rating | 3.5 |
Size | 2,667 Kb |
Views | 8,096 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Alphabetizing Lists with JavaScript | 2,719 Kb |
My First Mixin | 2,017 Kb |
Sorting Items While Ignoring Articles | 3,002 Kb |
Just Some Buttons | 1,568 Kb |
Sticky Footer | 1,655 Kb |
CSS Grid Using Inline-Block | 1,800 Kb |
Sass Mixin Example | 1,944 Kb |
Simple React Router | 2,707 Kb |
JavaScript Alphabetize Function | 2,596 Kb |
React Routing with this.props.children | 2,725 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Flower expansion | Sreucherand | 3,425 Kb |
Promodoro | Bencarp | 1,712 Kb |
Blog demo to use given styling | Andygirl | 2,412 Kb |
Brian The CSS Bee | Jonitrythall | 3,922 Kb |
Next Word Predictor | Rfalor | 2,776 Kb |
Svg sky | Omodev | 7,070 Kb |
Flat UI Button | Honchoman | 2,289 Kb |
SVG Animation | Thepheer | 4,793 Kb |
Expert Help | SinceSidSlid | 4,064 Kb |
Jquery 2d character movement | Drewtadams | 4,291 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!