How to create a navbar with a notification counter using bootstrap 4 ?

Active February 13, 2021    /    Viewed 3487    /    Comments 0    /    Edit


Examples of how to create a navbar with a notification counter using bootstrap 4:

Example 1

code

<span class="badge badge-pill badge-warning" style="float:right;margin-bottom:-15px;margin-right:-18px;font-size:10px">123</span>
<a class="nav-link" href="/News/">News <span class="sr-only">(current)</span></a>

How to create a navbar with a notification counter using bootstrap 4 ?

Full code:

<!DOCTYPE html>
<html lang="en">

<head>

<title>Test</title>

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

</head>

<body>

<nav class="navbar navbar-expand-lg navbar-default fixed-top navbar-dark" style="background-color: #3c3d41;" id="mainNav">

  <div class="container">

      <a class="navbar-brand" href="/" style="color:white">Hello World</a>

      <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsibleNavbar">
        <span class="navbar-toggler-icon"></span>
      </button>

      <div class="collapse navbar-collapse" id="collapsibleNavbar">
        <ul class="navbar-nav">    
            <li class="nav-item">
                <span class="badge badge-pill badge-warning" style="float:right;margin-bottom:-15px;margin-right:-18px;font-size:10px">123</span>
                <a class="nav-link" href="/News/">News <span class="sr-only">(current)</span></a>
            </li>         
        </ul>
      </div>

</div>
</nav>


</body>
</html>

Example 2

Changing the color:

badge-danger

How to create a navbar with a notification counter using bootstrap 4 ?

badge-info

How to create a navbar with a notification counter using bootstrap 4 ?

References


Card image cap
profile-image
Daidalos

Hi, I am Ben.

I have developed this web site from scratch with Django to share with everyone my notes. If you have any ideas or suggestions to improve the site, let me know ! (you can contact me using the form in the welcome page). Thanks!



Did you find this content useful ?, If so, please consider donating a tip to the author(s). MoonBooks.org is visited by millions of people each year and it will help us to maintain our servers and create new contents.

Amount