📅  最后修改于: 2023-12-03 15:29:38.428000             🧑  作者: Mango
Bootstrap is a popular front-end development framework that helps developers build responsive and mobile-friendly websites quickly and easily. One of its key features is a customizable navigation bar called the navbar, which can be used to add menus, links, buttons, and more to a webpage.
To get started with Bootstrap and navbar in HTML, you'll need to include the necessary files in your project:
<!-- CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<!-- JavaScript -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
Once you have the files in place, you can start building your navbar. Here's an example of a basic navbar with three links:
<nav class="navbar navbar-expand-md bg-dark navbar-dark">
<a class="navbar-brand" href="#">My Website</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarMenu">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarMenu">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact</a>
</li>
</ul>
</div>
</nav>
In this example, we're using the navbar
and navbar-expand-md
classes to create a dark navbar that expands to full size on medium devices and larger. The navbar-brand
class is used to create a clickable logo or site name, and the navbar-toggler
class is used to create a button that toggles the navbar menu on smaller devices.
Inside the navbar, we're using a collapse
class to create a hidden menu that expands on smaller devices. The navbar-nav
class is used to create a list of links, and the nav-item
class is used to style each list item. Finally, the nav-link
class is used to style each link.
Bootstrap and navbar in HTML make it easy to create professional-looking and responsive websites. With a little bit of HTML and CSS knowledge, you can customize your navbar to suit your needs and create a website that looks great on any device.