📅  最后修改于: 2023-12-03 14:39:33.063000             🧑  作者: Mango
Bootstrap Nav is a pre-designed navigation bar that is part of the Bootstrap framework. It is a responsive navbar that can collapse into a hamburger menu on smaller screens, and the menu items can be customized to fit any design needs.
To use Bootstrap Nav in your HTML project, you will first need to link to the Bootstrap CSS and JavaScript files.
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
Next, you can add the navbar code to your HTML file. Below is an example of the basic structure of a Bootstrap Nav.
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Brand Name</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 <span class="sr-only">(current)</span></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>
There are many ways to customize Bootstrap Nav to fit your design needs. Some examples include:
To change the background color of the navbar, you can add the bg-*
class to the nav
element. Replace the *
with the name of the desired color. For example, to make the background color blue, you can use the following code:
<nav class="navbar navbar-expand-lg navbar-light bg-primary">
To add a logo image to the navbar, you can include an img
element within the navbar-brand
link. For example:
<a class="navbar-brand" href="#"><img src="logo.png" alt="Company Logo"></a>
To add icons to the navbar links, you can use the font-awesome
library. First, include the font-awesome
CSS file in your HTML:
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
Then, include the icon classes in the nav-link
class. For example:
<a class="nav-link" href="#"><i class="fa fa-home"></i> Home</a>
Bootstrap Nav is an easy-to-use and customizable navigation bar that can save time and effort in creating a responsive menu for your website. With a few lines of code, you can have a great looking navigation bar that works on all screen sizes.