home강의 홈으로
Section 5. 파이널 프로젝트
Lesson 3. 헤더와 메뉴

👉 완성본 보기


<header class="header"> <h1> <a class="header__homelink" href="#"> <img class="header__logo" src="./images/logo.svg" alt="홈으로"> </a> </h1> <input class="header__menu-btn" type="checkbox"> <nav class="header__nav"> <ul> <li class="header__nav-item"> <a href="#about">얄코강좌는</a> </li> <li class="header__nav-item"> <a href="#html">HTML</a> </li> <li class="header__nav-item"> <a href="#css">CSS</a> </li> <li class="header__nav-item"> <a href="#curriculum">커리큘럼</a> </li> <li class="header__nav-item"> <a href="#contact">문의하기</a> </li> </ul> </nav> </header>

2-header.css


1. 헤더 배치

.header { display: flex; position: sticky; /* 스크롤업되는 컨텐츠 위로 올라오도록 */ z-index: 2; top: 0; height: var(--height-toolbar); justify-content: space-between; align-items: center; background-color: var(--color-main); color: white; }

2. 왼쪽 링크와 로고

.header__homelink { display: inline-block; padding: 0 24px; height: var(--height-toolbar); line-height: var(--height-toolbar); cursor: pointer; } .header__logo { height: 48px; vertical-align: middle; margin-bottom: 4px; }

3. 네비게이션

.header__nav-item { font-size: var(--font-size-larger); }

모바일

.header__nav { display: none; }

데스크탑

.header__nav-item { display: inline-block; position: relative; } .header__nav-item:last-child { margin-right: 1.6em; }

4. 네비게이션 링크

.header__nav-item a { /* 클릭 영역 확대 */ display: inline-block; height: var(--height-toolbar); line-height: var(--height-toolbar); }

데스크탑

.header__nav-item a { padding: 0 0.8em; }

5. 네비게이션 롤오버 효과

데스크탑

.header__nav-item::after { content: ''; position: absolute; bottom: 0px; left: 50%; width: 0; height: 0; background-color: white; transition: all 350ms; } .header__nav-item:hover::after { left: 0; width: 100%; height: 8px; }

6. 모바일 메뉴 버튼

모바일

/* 체크박스 인풋을 버튼으로 커스터마이즈 */ .header__menu-btn { all: unset; display: block; width: var(--height-toolbar); height: var(--height-toolbar); background-image: url(../images/menu-button.svg); background-size: 50%; background-repeat: no-repeat; background-position: center; } .header__menu-btn:checked { background-color: var(--color-dark); }

데스크탑

.header__menu-btn { display: none; }

7. 모바일 메뉴 팝업

모바일

.header__menu-btn:checked + .header__nav { display: inherit; position: absolute; top: var(--height-toolbar); right: 0; background-color: var(--color-dark); padding-bottom: 1em; box-shadow: 0 2px 2px rgba(0, 0, 0, 0.2); } .header__nav-item { width: 100vw; text-align: center; } .header__nav-item a { width: 100vw; } .header__nav-item:not(:last-child) { border-bottom: 2px solid rgba(255, 255, 255, 0.06); }

🤔얄코에게 질문하기질문은 반.드.시 이리로 보내주세요! ( 강의사이트 질문기능 ✖ )

강의에서 이해가 안 되거나 실습상 문제가 있는 부분,
설명이 잘못되었거나 미흡한 부분을 메일로 알려주세요!

답변드린 뒤 필요할 경우 본 페이지에
관련 내용을 추가/수정하도록 하겠습니다.

이메일 주소
yalco@yalco.kr
메일 제목 (반드시 아래 제목을 붙여넣어주세요!)
[질문] 제대로 파는 HTML & CSS (유료 파트) 5-3

🛑질문 전 필독!!

  • 구글링을 먼저 해 주세요. 들어오는 질문의 절반 이상은 구글에 검색해 보면 1분 이내로 답을 찾을 수 있는 내용들입니다.
  • 오류 메시지가 있을 경우 이를 구글에 복붙해서 검색해보면 대부분 짧은 시간 내 해결방법을 찾을 수 있습니다.
  • 강의 페이지에 추가사항 등 놓친 부분이 없는지 확인해주세요. 자주 들어오는 질문은 페이지에 추가사항으로 업데이트됩니다.
  • "유료파트의 강의페이지는 어디 있나요?" - 각 영상의 시작부분 검은 화면마다 해당 챕터의 강의페이지 링크가 있습니다.
  • 질문을 보내주실 때는 문제가 어떻게 발생했고 어떤 상황인지 등을 구체적으로 적어주세요. 스크린샷을 첨부해주시면 더욱 좋습니다.
🌏 Why not change the world?