Created
February 25, 2020 13:42
-
-
Save Lucas-Severo/8ee3e6dcdf61b68135aff974f2d1b95e to your computer and use it in GitHub Desktop.
Responsive navbar
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
| <!DOCTYPE html> | |
| <html lang="pt-br"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
| <title>navbar</title> | |
| <link rel="stylesheet" href="css/style.css"> | |
| <script src="https://kit.fontawesome.com/5773d4ffcc.js" crossorigin="anonymous"></script> | |
| </head> | |
| <body> | |
| <header> | |
| <h1>logo</h1> | |
| <nav> | |
| <ul> | |
| <li><a href="#">Home</a></li> | |
| <li><a href="#">About</a></li> | |
| <li><a href="#">Services</a></li> | |
| <li><a href="#">Portfolio</a></li> | |
| <li><a href="#">Contact</a></li> | |
| </ul> | |
| <div class="open"><i class="fas fa-bars"></i></div> | |
| <div class="close"><i class="fas fa-times"></i></div> | |
| </nav> | |
| </header> | |
| <script src="js/script.js"></script> | |
| </body> | |
| </html> |
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
| const openButton = document.querySelector(".open"); | |
| const closeButton = document.querySelector(".close"); | |
| const navElement = document.querySelector("nav"); | |
| openButton.addEventListener("click", function(){ | |
| navElement.className = "activated"; | |
| }) | |
| closeButton.addEventListener("click", function() { | |
| navElement.className = ""; | |
| }) |
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
| * { | |
| padding: 0; | |
| margin: 0; | |
| font-family: Arial, Helvetica, sans-serif; | |
| box-sizing: border-box; | |
| } | |
| header { | |
| display: flex; | |
| justify-content: space-around; | |
| align-items: center; | |
| text-transform: uppercase; | |
| background-color: #5171A5; | |
| padding: 30px 0px; | |
| } | |
| nav { | |
| transition: left 0.4s; | |
| } | |
| nav ul{ | |
| display: flex; | |
| list-style: none; | |
| } | |
| nav li a{ | |
| text-decoration: none; | |
| color: black; | |
| padding: 10px 20px; | |
| font-size: 20px; | |
| } | |
| nav li a:hover { | |
| color: #3F3047; | |
| background-color: #e40344; | |
| } | |
| .open, .close { | |
| position: absolute; | |
| top: 30px; | |
| right: 70px; | |
| font-size: 30px; | |
| cursor: pointer; | |
| display: none; | |
| } | |
| .activated { | |
| position: absolute; | |
| top: 0; | |
| left: 0; | |
| width: 100%; | |
| height: 100vh; | |
| background-color: black; | |
| } | |
| .activated ul { | |
| display: flex; | |
| flex-direction: column; | |
| justify-content: center; | |
| align-items: center; | |
| height: 100%; | |
| } | |
| .activated li { | |
| padding: 30px 0px; | |
| } | |
| .activated li a { | |
| color: white; | |
| } | |
| .activated .close { | |
| display: block; | |
| color: white; | |
| } | |
| @media (max-width: 768px) { | |
| nav { | |
| left: 100%; | |
| } | |
| nav ul { | |
| display: none; | |
| } | |
| .open { | |
| display: block; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment