🐨CoalaCoding
DocsExamplesTry itBoardB반
🐨CoalaCoding

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

문서

  • JavaScript
  • Web Publishing
  • React
  • Python

커뮤니티

  • 게시판
  • 예제 모음
  • Try it 에디터

기타

  • GitHub
  • 관리자
© 2026 CoalaCoding. All rights reserved.
  • 01_변수
  • 02_mask
  • 03_기본문법과-선택자
  • 04_네스팅
  • 05_svg
  • 06_가로스크롤
  • 07_문자
  • 08_반응형-폰트크기
  • 09_문단
  • 10_리퀴드글래스
  • 11_배경
  • 12_세로정렬
  • 13_박스모델
  • 14_레이아웃
  • 15_트랜지션과-애니메이션
  • 10_svg
  • 11_폼디자인
  • 12_clamp(),min(),max()
  • 14_calc
  • 15_animation
  • 16_transition
  • 1_선택자
  • 2_hover효과
  • 3_var
  • 4_클립패스
  • 5_마스크
  • 6_containerQuery
  • 7_retina
  • 8_반응형 햄버거메뉴
  • 9_transform
  • 05_ 반응형 디자인과 접근성
  1. 홈
  2. 문서
  3. HTML & CSS
  4. CSS
  5. 8_반응형 햄버거메뉴

8_반응형 햄버거메뉴

코드 블록의 Try it Yourself 버튼으로 직접 실행할 수 있다.

구문

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');
});

목차

  • 구문