📅  最后修改于: 2023-12-03 14:59:33.735000             🧑  作者: Mango
The Bootstrap 4 Navbar is a component that provides a responsive navigation bar for websites and web applications. It makes it easy to create a stylish and functional navigation menu that adapts to different screen sizes.
To use the Bootstrap 4 Navbar, you need to include the Bootstrap CSS and JavaScript files in your project. Then, you can use the following HTML structure to create the navbar:
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Logo</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<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="#">Services</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact</a>
</li>
</ul>
</div>
</nav>
In the above example, the navbar is created with a light background color (bg-light
). The brand logo is added using the navbar-brand
class, and the navigation links are placed inside a collapsible container. The navbar-toggler
button enables the collapsible behavior.
You can further customize the navbar by adding additional classes provided by Bootstrap or by adding your own CSS rules.
The Bootstrap 4 Navbar is a versatile component that helps you create a responsive and user-friendly navigation bar for your website or web application. With its numerous features and customization options, you can easily create a navigation menu that aligns with your project's requirements.