🐨CoalaCoding
Docs▾
JavaScriptReactHTML & CSSBackendAI & LLMDev ToolsCreative
B반1
👾숏츠
🙉B반2
게시판
🐨CoalaCoding

개발자를 위한 한국어 웹 기술 문서

문서

  • JavaScript
  • React
  • HTML & CSS
  • Backend
  • AI & LLM
  • Dev Tools
  • Creative

커뮤니티

  • 게시판
  • 예제 모음

기타

  • 관리자

정책

  • 소개
  • 개인정보처리방침
  • 이용약관
  • 연락처
© 2026 CoalaCoding. All rights reserved.
  • 1. 선택자
  • 2. 문자
  • 3. 문단
  • 4. 박스모델
  • 5. 배경
  • 6. 레이아웃
  • 7. 트랜지션과-애니메이션
  • 8. 마스크
  • 10. hover효과
  • 11. var
  • 12. 클립패스
  • 13. 네스팅
  • 15. containerQuery
  • 16. 가로스크롤
  • 17. retina
  • 18. 반응형 햄버거메뉴
  • 19. 반응형-폰트크기
  • 20. svg
  • 21. 리퀴드글래스
  • 22. 폼디자인
  • 23. clamp(),min(),max()
  • 24. 세로정렬
  • 25. calc
  1. 홈
  2. 문서
  3. HTML & CSS
  4. CSS
  5. 18. 반응형 햄버거메뉴

18. 반응형 햄버거메뉴

8.반응형 햄버거메뉴

1. 자바스크립트

미리보기

index.html

<!DOCTYPE html>
<html lang="ko">
	<head>
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>Responsive Navigation Bar</title>
		
		<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" />
		
		<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@600;700&display=swap" rel="stylesheet" />
		
		<link rel="stylesheet" href="style.css" />
	</head>
	<body>
		<header>
			<nav>
				<a href="#home" id="logo">Site Logo</a>
				<i class="fas fa-bars" id="ham-menu"></i>
				<ul id="nav-bar">
					<li>
						<a href="#home">Home</a>
					</li>
					<li>
						<a href="#about">About</a>
					</li>
					<li>
						<a href="#services">Services</a>
					</li>
					<li>
						<a href="#team">Team</a>
					</li>
					<li>
						<a href="#contact">Contact</a>
					</li>
				</ul>
			</nav>
		</header>
		<section id="home">
			<h1>Home Section</h1>
		</section>
		
		<script src="script.js"></script>
	</body>
</html>

style.css

* {
	padding: 0;
	margin: 0;
	box-sizing: border-box;
}
html {
	font-size: 62.5%;
}
*:not(i) {
	font-family: 'Poppins', sans-serif;
}
header {
	position: fixed;
	width: 100%;
	background-color: #2c8eec;
	padding: 3rem 5rem;
}
nav {
	display: flex;
	justify-content: space-between;
	align-items: center;
}
nav ul {
	list-style: none;
	display: flex;
	gap: 2rem;
}
nav a {
	font-size: 1.8rem;
	text-decoration: none;
}
nav a#logo {
	color: #000000;
	font-weight: 700;
}
nav ul a {
	color: #ffffff;
	font-weight: 600;
}
nav ul a:hover {
	border-bottom: 2px solid #ffffff;
}
section#home {
	height: 100vh;
	display: grid;
	place-items: center;
}
h1 {
	font-size: 4rem;
}
#ham-menu {
	display: none;
}
nav ul.active {
	left: 0;
}
@media only screen and (max-width: 991px) {
	html {
		font-size: 56.25%;
	}
	header {
		padding: 2.2rem 5rem;
	}
}
@media only screen and (max-width: 767px) {
	html {
		font-size: 50%;
	}
	#ham-menu {
		display: block;
		color: #ffffff;
	}
	nav a#logo,
	#ham-menu {
		font-size: 3.2rem;
	}
	nav ul {
		background-color: black;
		position: fixed;
		left: -100vw;
		top: 73.6px;
		width: 100vw;
		height: calc(100vh - 73.6px);
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: space-around;
		transition: 1s;
		gap: 0;
	}
}
@media only screen and (max-width: 575px) {
	html {
		font-size: 46.87%;
	}
	header {
		padding: 2rem 3rem;
	}
	nav ul {
		top: 65.18px;
		height: calc(100vh - 65.18px);
	}
}

script.js

let hamMenuIcon = document.getElementById('ham-menu');
let navBar = document.getElementById('nav-bar');
let navLinks = navBar.querySelectorAll('li');

hamMenuIcon.addEventListener('click', () => {
	navBar.classList.toggle('active');
	hamMenuIcon.classList.toggle('fa-times');
});
navLinks.forEach((navLinks) => {
	navLinks.addEventListener('click', () => {
		navBar.classList.remove('active');
		hamMenuIcon.classList.toggle('fa-times');
	});
});

2. 제이쿼리로 구현하기

index.html

...생략
  
  <script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
  <script src="jquery.js"></script>
</body>

jquery.js

let hamMenuIcon = $('#ham-menu');
let navBar = $('#nav-bar');
let navLinks = $('li');

hamMenuIcon.click(function () {
	navBar.toggleClass('active');
	hamMenuIcon.toggleClass('fa-times');
});
navLinks.click(function () {
	navBar.removeClass('active');
	hamMenuIcon.toggleClass('fa-times');
});

목차

  • 1. 자바스크립트
  • index.html
  • style.css
  • script.js
  • 2. 제이쿼리로 구현하기
  • index.html
  • jquery.js