![](https://maz.kr/wp-content/uploads/2024/04/howto-css-navbar-image-thumbnail.png)
w3.css
이미지의 Navbar
CSS를 사용하여 이미지에 탐색 메뉴를 추가하는 방법을 알아보자.
이미지에 Navbar를 만드는 방법
1단계) HTML 추가
탐색 모음을 만든다.
<div class="bg-img"> <div class="container"> <div class="topnav"> <a href="#home">Home</a> <a href="#news">News</a> <a href="#contact">Contact</a> <a href="#about">About</a> </div> </div> </div>
2단계) CSS 추가
탐색 모음 스타일을 지정한다.
.bg-img { /* The image used */ background-image: url("img_nature.jpg"); min-height: 380px; /* Center and scale the image nicely */ background-position: center; background-repeat: no-repeat; background-size: cover; /* Needed to position the navbar */ position: relative; } /* Position the navbar container inside the image */ .container { position: absolute; margin: 20px; width: auto; } /* The navbar */ .topnav { overflow: hidden; background-color: #333; } /* Navbar links */ .topnav a { float: left; color: #f2f2f2; text-align: center; padding: 14px 16px; text-decoration: none; font-size: 17px; } .topnav a:hover { background-color: #ddd; color: black; }
기본 예시
예제 보기참고
W3C School - How TO - Navbar on Image