여러분이 사용하고 계신 브라우저는 HTML5를 지원하지 않기 때문에 몇몇 요소가 제대로 보이도록 JScript를 사용하고 있습니다. 하지만 여러분의 브라우저 설정에서 스크립트 기능이 꺼져있으므로, 현재 페이지를 제대로 확인하시려면 스크립트 기능을 켜주셔야 합니다. How To - 고정 메뉴
How To – 고정 메뉴
3개월전 작성
3개월전 수정

w3.css

고정 메뉴

CSS를 사용하여 “고정” 메뉴를 만드는 방법을 알아보자.

고정 상단 메뉴를 만드는 방법

1단계) HTML 추가
<div class="navbar">
  <a href="#home">Home</a>
  <a href="#news">News</a>
  <a href="#contact">Contact</a>
</div>

<div class="main">
  <p>Some text some text some text some text..</p>
</div>
2단계) CSS 추가

고정 상단 메뉴를 생성하려면 position:fixed및 top:0를 사용하자.
고정 메뉴는 다른 콘텐츠와 겹쳐진다.
이 문제를 해결하려면 메뉴 높이보다 크거나 같은 margin-top(콘텐츠에)을 추가하자.

/* The navigation bar */
.navbar {
  overflow: hidden;
  background-color: #333;
  position: fixed; /* Set the navbar to fixed position */
  top: 0; /* Position the navbar at the top of the page */
  width: 100%; /* Full width */
}

/* Links inside the navbar */
.navbar a {
  float: left;
  display: block;
  color: #f2f2f2;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
}

/* Change background on mouse-over */
.navbar a:hover {
  background: #ddd;
  color: black;
}

/* Main content */
.main {
  margin-top: 30px; /* Add a top margin to avoid content overlay */
}
기본 예시
예제 보기

고정 하단 메뉴를 만드는 방법

고정 하단 메뉴를 만들려면 position:fixed 및 다음 bottom:0을 사용하자.

예제
/* The navigation bar */
.navbar {
  position: fixed; /* Set the navbar to fixed position */
  bottom: 0; /* Position the navbar at the bottom of the page */
  width: 100%; /* Full width */
}

/* Main content */
.main {
  margin-bottom: 30px; /* Add a bottom margin to avoid content overlay */
}
기본 예시
예제 보기
참고
Mingg`s Diary
밍구
공부 목적 블로그