How to add a background image to the navbar in bootstrap 5?
January 30, 2023Hi Friends 👋,
Welcome To aGuideHub! ❤️
To add a background image to the navbar in bootstrap 5, use the background-image: url("image/flower.jpg");
. It will add a background image to the navbar in bootstrap 5.
Today, I am going to show you. how to add a background image to the navbar in bootstrap 5 with code example.
Table of contents
- Includes bootstrap view
- Includes bootstrap library
- Example of background image to the navbar in bootstrap
This article will guide you to add a background image to the navbar in bootstrap 5 with an example.
Includes bootstrap view
To ensure proper rendering and touch zooming for all devices, add the responsive viewport meta tag to your <head>
.
<meta name="viewport" content="width=device-width, initial-scale=1">
Includes bootstrap library
First of all, load the Bootstrap framework CSS into the head tag of your webpage.
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
Example of background image to the navbar in bootstrap
In this example, we will add the navigation bar with this code background-image: url("image/flower.jpg");
and background-repeat: no-repeat;
and background-size: cover;
.
Let’s look at the following example to understand how it works:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Create a button with a background image in bootstrap</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<style>
.container-fluid{
background-image: url("image/flower.jpg");
background-repeat: no-repeat;
background-size: cover;
}
</style>
</head>
<body>
<nav class="navbar navbar-expand mt-3">
<div class="container-fluid bg-dark">
<div class="navbar-nav">
<a class="nav-link text-light">One</a>
<a class="nav-link text-light">Two</a>
<a class="nav-link text-light">Three</a>
<a class="nav-link text-light">Four</a>
</div>
<div class="w-100"></div>
</div>
</nav>
</body>
</html>
Check the output of the above code example.
Try the below codesandbox link to customize the above example as per your requirement.
All the best 👍