Skip to content

Instantly share code, notes, and snippets.

@kicktv
Last active November 17, 2024 21:12
Show Gist options
  • Save kicktv/067686f6f446854b4b41e55acff9c2d6 to your computer and use it in GitHub Desktop.
Save kicktv/067686f6f446854b4b41e55acff9c2d6 to your computer and use it in GitHub Desktop.
menu navbar responsive
<!-- preview html https://gist.githack.com/kicktv/067686f6f446854b4b41e55acff9c2d6/raw/menu.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">
<!-- App title -->
<title>Responsive Pure CSS Menu</title>
<!-- Link css file -->
<!-- <link rel="stylesheet" href="https://raw.githack.com/Ivy-Walobwa/responsive-pure-css-menu/main/style.css"> -->
<style>
/* Theming */
@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@400;700&display=swap");
:root{
--white: #f9f9f9;
--black: #36383F;
--grey: #85888C;
}
/* Reset */
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
body{
background-color: var(--white);
font-family: "Poppins", sans-serif;
}
a{
text-decoration: none;
}
ul{
list-style: none;
}
/* Header */
.header{
background-color: var(--black);
box-shadow: 1px 1px 5px 0px var(--grey);
position: sticky;
top: 0;
width: 100%;
}
/* Logo */
.logo{
display: inline-block;
color: var(--white);
font-size: 60px;
margin-left: 10px;
}
/* Nav menu */
.nav{
width: 100%;
height: 100%;
position: fixed;
background-color: var(--black);
overflow: hidden;
}
.menu a{
display: block;
padding: 30px;
color: var(--white);
}
.menu a:hover{
background-color: var(--grey);
}
.nav{
max-height: 0;
transition: max-height .5s ease-out;
}
/* Menu Icon */
.hamb{
cursor: pointer;
float: right;
padding: 40px 20px;
}
.hamb-line {
background: var(--white);
display: block;
height: 2px;
position: relative;
width: 24px;
}
.hamb-line::before,
.hamb-line::after{
background: var(--white);
content: '';
display: block;
height: 100%;
position: absolute;
transition: all .2s ease-out;
width: 100%;
}
.hamb-line::before{
top: 5px;
}
.hamb-line::after{
top: -5px;
}
.side-menu {
display: none;
}
/* Toggle menu icon */
.side-menu:checked ~ nav{
max-height: 100%;
}
.side-menu:checked ~ .hamb .hamb-line {
background: transparent;
}
.side-menu:checked ~ .hamb .hamb-line::before {
transform: rotate(-45deg);
top:0;
}
.side-menu:checked ~ .hamb .hamb-line::after {
transform: rotate(45deg);
top:0;
}
/* Responsiveness */
@media (min-width: 768px) {
.nav{
max-height: none;
top: 0;
position: relative;
float: right;
width: fit-content;
background-color: transparent;
}
.menu li{
float: left;
}
.menu a:hover{
background-color: transparent;
color: var(--grey);
}
.hamb{
display: none;
}
}
</style>
</head><body>
<!-- Navigation bar -->
<header class="header">
<!-- Logo -->
<a href="#" class="logo">LOGO</a>
<!-- Hamburger icon -->
<input class="side-menu" type="checkbox" id="side-menu"/>
<label class="hamb" for="side-menu"><span class="hamb-line"></span></label>
<!-- Menu -->
<nav class="nav">
<ul class="menu">
<li><a href="#">Gallery</a></li>
<li><a href="#">Blog</a> </li>
<li><a href="#">About</a></li>
</ul>
</nav>
</header>
<br><br>
<!-- Main content -->
<main> <center>
<article>
<h1>Some content</h1>
<p>
More Content
</p>
</article>
</center>
</main>
</body>
</html>
@kicktv
Copy link
Author

kicktv commented Nov 17, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment