Skip to content

Commit

Permalink
hamburger menu for media query added
Browse files Browse the repository at this point in the history
  • Loading branch information
fikretellek committed Dec 19, 2024
1 parent 0795ef8 commit d75bd9e
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/components/Header/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ import { useState } from "react";
import "./Header.scss";

const Header = (props) => {
const handleToggleMenu = (e) => {
if (document.getElementsByTagName("nav")[0].classList.contains("hiden")) {
document.getElementsByTagName("nav")[0].classList.remove("hiden");
e.target.classList.add("close");
} else {
document.getElementsByTagName("nav")[0].classList.add("hiden");
e.target.classList.remove("close");
}
};
return (
<>
<header>
Expand All @@ -15,8 +24,12 @@ const Header = (props) => {
<div></div>
</div>
</a>
<button id="hamburger-menu" onClick={handleToggleMenu}>
<div className="menu-bar"></div>
<div className="menu-bar"></div>
</button>

<nav>
<nav className="hiden">
<a href="#projects" onClick={() => props.handleLinkClick("#projects")}>
<p className={props.activeLink === "#projects" ? "activeNav" : ""}>Projects</p>
</a>
Expand Down
66 changes: 66 additions & 0 deletions src/components/Header/Header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,69 @@ header {
grid-area: f;
}
}

#hamburger-menu {
display: none;
}

@media screen and (max-width: 768px) {
header {
nav {
border-radius: var(--border-radius) 0px 0px var(--border-radius);
padding-left: 30%;
max-width: 500px;
position: absolute;
padding-top: calc(3 * var(--gap));
padding-bottom: calc(3 * var(--gap));
top: 100%;
right: 0%;
background-color: var(--color-hover);
width: calc(50% - 2 * var(--gap));
display: flex;
flex-direction: column;
align-items: flex-start;
justify-content: center;

&.hiden {
left: 100%;
}
}

#hamburger-menu {
border: none;
margin: 0px;
padding: 0px;
background-color: var(--bg-color);
width: 50px;
height: 50px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: flex-end;
gap: var(--gap);

.menu-bar {
transition: all 0.3s ease;
pointer-events: none;
width: 50px;
height: 5px;
background-color: var(--color);
&:nth-child(2) {
width: 40px;
}
}
&.close {
.menu-bar {
width: 50px;
height: 5px;
background-color: var(--color);
transform: rotate(45deg) translateY(10px);
&:nth-child(2) {
width: 50px;
transform: rotate(-45deg) translateY(-10px);
}
}
}
}
}
}

0 comments on commit d75bd9e

Please sign in to comment.