방법 - 고정 메뉴
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 */
}
팁: 탐색 모음에 대해 자세히 알아보려면 CSS Navbar 자습서 로 이동하십시오 .