Simple Responsive Menu Bar
If you are looking for how to create a responsive menu bar very easy way, then I think this little code snippet is that what you are looking for...
Ingrediants
- HTML
- CSS
Main Focus Point:
- In HTML
- input (id = checked)
- label (for = checked)
- In CSS
- ul { flex }
- media queary ( 600px )
- ul { flex + column }
- position : absolute
- top : 70px
- left : -100%
- #checked : checked ~ ul { left : 0 }
HTML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Responsive Menu</title> <link rel="stylesheet" href="style.css"> <!--For Bar Icon--> <script src="https://kit.fontawesome.com/1f45fef13f.js" crossorigin="anonymous"></script> </head> <body> <header> <nav> <input type="checkbox" id="checked"> <label for="checked" class="checkLebel"> <i class="fas fa-bars"></i> </label> <ul> <li><a href="#Home">Home</a></li> <li><a href="#Service">Service</a></li> <li><a href="#About">About</a></li> <li><a href="#Contact">Contact</a></li> <li><a href="#Login">Login</a></li> </ul> </nav> </header> </body> </html>
CSS
* { margin : 0; padding : 0; box-sizing : border-box; list-style : none; text-decoration: none; } body { font-family: 'Trebuchet MS'; } nav { background-color: lightgoldenrodyellow; height : 70px; } ul { display : flex; justify-content: flex-end; margin-right : 20px; } ul li { margin-top : 15px; margin-left : 10px; border : .5px solid black; border-radius: 3px; padding : 10px 20px; cursor : pointer; } ul li a { color: black; } ul li:hover { background-color: coral; } .checkLebel { font-size: 35px; float : right; margin : 10px 25px 0 0; cursor : pointer; display : none; } #checked { display: none; } @media (max-width: 600px) { ul { width : 100%; min-height : 100vh; display : flex; flex-flow : column; text-align : center; justify-content : flex-start; position : absolute; top : 70px; left : -100%; background-color: cadetblue; transition : all .5s ease-in-out; } ul li:last-child { margin-bottom: 20px; } ul li { display: inline-block; margin : 20px 10px 0 10px; } .checkLebel { display: block; } #checked:checked~ul { left: 0; } }
Comments
Post a Comment