Hambergur icon not displaying collapsed navbar items - html

I am making a react application and using bootstrap navbar to make it mobile responsive but the hamburger icon is not displaying the items of navbar collapsed what is wrong here? any suggestions?
<!-- Bootstrap 4.1.3 library -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<!-- Start of HTML code -->
<header id="header" className="fixed-top d-flex align-items-center header-transparent">
<div className="container d-flex align-items-center navbar navbar-expand-lg navbar-light navbar-inverse ">
<div className="logo mr-auto">
<h1 className="text-light heading"><span>Prep</span></h1>
</div>
<button className="navbar-toggler navbar-dark" type="button" data-toggle="collapse" data-target="#navbarmenu" aria-expanded="false" aria-label="Toggle navigation">
<span className="navbar-toggler-icon"></span>
</button>
<nav className="nav-menu d-none d-lg-block">
<div className="collapse navbar-collapse" id="navbarmenu">
<ul className="navbar-nav mr-auto">
<li className="nav-item">About</li>
<li className="nav-item">Features</li>
<li className="nav-item">Team</li>
<li className="nav-item">Contact</li>
<li className="nav-item">FAQs</li>
<li className="nav-item">
<Link to="/signup">Register</Link>
</li>
</ul>
</div>
</nav>
</div>
</header>

I have done this for you . You can see it in your react code how it works . Because I haven't installed react now .But using botstrap I have done this. You can check .
here is code snippets:
<nav className='navbar navbar-dark navbar-expand-lg bg-dark'>
Prep
<button className="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarmenu" aria-expanded="false" aria-label="Toggle navigation"><span className="navbar-toggler-icon"></span>
</button>
<div className="collapse navbar-collapse" id="navbarmenu">
<ul className="navbar-nav mr-auto">
<li className="nav-item"><a className='nav-link' href="#about">About</a></li>
<li className="nav-item"><a className='nav-link' href="#details">Features</a></li>
<li className="nav-item"><a className='nav-link' href="#team">Team</a></li>
<li className="nav-item"><a className='nav-link' href="#contact">Contact</a></li>
<li className="nav-item"><a className='nav-link' href="#faq">FAQs</a></li>
<li className="nav-item"><Link to="/signup">Register</Link></li>
</ul>
</div>
</nav>
This is the convinient way how you can fix this issue and its really easy. You are using jsx If this works fine I will be happy as a developer.

If you are using CDN links make sure you have included jQuery link and if you are using npm install bootstrap make sure you have imported bootstrap import 'bootstrap';

Related

Bootstrap 5.1.3 Nav-Bar (button) collapse button not functioning properly

Once I click on the collapsed nav-bar button it expands and shows the nav-bar contents but after again clicking on the button it does not collapse again. Below is the html code.
*<!-- CSS Stylesheet -->*
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
*<!-- Bootstap Scripts -->*
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/#popperjs/core#2.10.2/dist/umd/popper.min.js" integrity="sha384-7+zCNj/IqJ95wo16oMtfsKbZ9ccEh31eOz1HGyDuCQ6wgnyJNSYdrPa03rtR1zdB" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/js/bootstrap.min.js" integrity="sha384-QJHtvGhmr9XOIpI6YVutG+2QOK9T+ZnN4kzFN1RtK3zEFEIsxhlmWl5/YESvpZ13" crossorigin="anonymous"></script>
<nav class="navbar fixed-top navbar-expand-lg navbar-dark" style="background-color: #95D1CC;">
<div class="container-fluid">
<a class="navbar-brand" href="#">Simon Game</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ms-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link" aria-current="page" href="CSS-My Site/about_index.html">About Developer</a>
</li>
<li class="nav-item">
<a class="nav-link" href="Instructions/instructions_index.html">Instructions</a>
</li>
</ul>
</div>
</div>
</nav>
You are including it all twice. It won't work this way.
You should EITHER include bootstrap.bundle.min.js OR (popper.min.js + bootstrap.min.js).
I had the same problem, and in my case I was inadvertedly doing this, which is wrong and causes the same problem:
import "bootstrap"
import "bootstrap/js/src/collapse"; // remove, otherwise it will not work

custom css navbarissues, which won't working in mobile

What is missing in my code, nav is not working on mobile screens, have I missed any tag with respect to menu bar?
<nav class="navbar navbar-expand-lg bg-white text-uppercase fixed-top" style="border-bottom: .125rem solid #fc9a00;">
<div class="container">
<a class="navbar-brand" href="index.html"><img src="images/top_logo.3bfa77.gif" alt="logo" /></a>
<button class="navbar-toggler text-uppercase font-weight-bold bg-primary rounded" type="button" data-bs-toggle="collapse" data-bs-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
Menu
<i class="fas fa-bars"></i>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ms-auto">
<li class="nav-item dropdown mx-0 mx-lg-1">
Company
<div class="dropdown-menu">
Greeting
</div>
</li>
<li class="nav-item dropdown mx-0 mx-lg-1">
Services
<div class="dropdown-menu">
test
</div>
</li>
</ul>
</div>
</div>
</nav>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://use.fontawesome.com/releases/v5.15.3/js/all.js" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
It seams you did not add bootstraps css and javascript. This works for me
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
<script src="https://use.fontawesome.com/releases/v5.15.3/js/all.js" crossorigin="anonymous"></script>
<nav class="navbar navbar-expand-lg bg-white text-uppercase fixed-top" style="border-bottom: .125rem solid #fc9a00;">
<div class="container">
<a class="navbar-brand" href="index.html"><img src="images/top_logo.3bfa77.gif" alt="logo" /></a>
<button class="navbar-toggler text-uppercase font-weight-bold bg-primary rounded" type="button" data-bs-toggle="collapse" data-bs-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
Menu
<i class="fas fa-bars"></i>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ms-auto">
<li class="nav-item dropdown mx-0 mx-lg-1">
Company
<div class="dropdown-menu">
Greeting
</div>
</li>
<li class="nav-item dropdown mx-0 mx-lg-1">
Services
<div class="dropdown-menu">
test
</div>
</li>
</ul>
</div>
</div>
</nav>

Why is my Bootstrap [4.2] Navbar Toggler not working?

I'm trying to make a responsive Navbar with Bootstrap Version 4.2 (I know its "old") but somehow it isn't working as expected. When I click on the hamburger symbol, nothing happens. Can anyone look after the mistake I made in the code below?
I googled a lot, checked the script order, but nothing worked.
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.2/css/all.css" integrity="sha384-vSIIfh2YWi9wW0r9iZe7RJPrKwp6bG+s9QZMoITbCckVJqGCCRhc+ccxNcdpHuYu" crossorigin="anonymous">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
<!-- Own CSS -->
<link rel="stylesheet" type='text/css' href="./css/style.css">
<title>Website Title</title>
<!-- Navbar -->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container">
Blogtopia
<button type="button" class="navbar-toggler" data-toggle="collapse" date-target="#navbarcollapse" aria-controls="navbarcollapse" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarcollapse">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<i class="fas fa-user"></i> My Profile
</li>
<li class="nav-item">
Dashboard
</li>
<li class="nav-item">
Posts
</li>
<li class="nav-item">
Categories
</li>
<li class="nav-item">
Manage Admins
</li>
<li class="nav-item">
Comments
</li>
<li class="nav-item">
Live Blog
</li>
</ul>
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<i class="fas fa-sign-out-alt"></i> Logout
</li>
</ul>
</div>
</div>
</nav>
<!-- Bootstrap Javascript -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
Thank you very much!
It's a typo – you wrote date-target
, but it should be data-target:
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.2/css/all.css" integrity="sha384-vSIIfh2YWi9wW0r9iZe7RJPrKwp6bG+s9QZMoITbCckVJqGCCRhc+ccxNcdpHuYu" crossorigin="anonymous">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container">
Blogtopia
<button type="button" class="navbar-toggler" data-toggle="collapse" data-target="#navbarcollapse" aria-controls="navbarcollapse" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarcollapse">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<i class="fas fa-user"></i> My Profile
</li>
<li class="nav-item">
Dashboard
</li>
<li class="nav-item">
Posts
</li>
<li class="nav-item">
Categories
</li>
<li class="nav-item">
Manage Admins
</li>
<li class="nav-item">
Comments
</li>
<li class="nav-item">
Live Blog
</li>
</ul>
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<i class="fas fa-sign-out-alt"></i> Logout
</li>
</ul>
</div>
</div>
</nav>

Bootstrap navbar, why is my navbar not expanding properly

Could someone help me fix my navbar ? It is not expanding properly when clicking on the toggler, im sure i've misplaced a div but I have moved around elements with very little success...
<header class="site-header" role="banner">
<div class="navbar-wrapper">
<nav class="navbar navbar-light bg-light navbar-expand-lg ">
<button class="navbar-toggler collapsed" type="button" data-toggle="collapse" data-target="#navbarToggler" aria-controls="navbarToggler" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<!-- end button -->
<a class="navbar-brand" src="index.html"><img class="logo-brand"src="img/kin.jpg" alt="header icon"></a>
<!-- collapsed section -->
<div class="navbar-collapse collapse" id="navbarToggler">
<!-- ml-auto for right and mr-auto for left -->
<ul class="navbar-nav mr-auto mt-2 mt-lg-0">
<li class="nav-item active"><a class="nav-link" href="#">Home</a>
</li>
<li class="nav-item"><a class="nav-link" href="#">Activities</a></li>
</ul>
</div>
</nav> <!--navbar -->
</div><!--navbar wrapper-->
</header>
I've compared it to a code that works and cannot find the difference... anyone with a good eye to fix me mistake ?
Ive copied a working collapsing navbar in my code and the same thing happens it the wrapper wont expand while the text comes out of its parent
Thanks
Take a look at following example:
Your code has no problem.
Be sure you provide right links for libraries. I added bootstrap css and js library links. And it needs Jquery before bootsrap js link.
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet"/>
<header class="site-header" role="banner">
<div class="navbar-wrapper">
<nav class="navbar navbar-light bg-light navbar-expand-lg ">
<button class="navbar-toggler collapsed" type="button" data-toggle="collapse" data-target="#navbarToggler" aria-controls="navbarToggler" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<!-- end button -->
<a class="navbar-brand" src="index.html"><img class="logo-brand"src="img/kin.jpg" alt="header icon"></a>
<!-- collapsed section -->
<div class="navbar-collapse collapse" id="navbarToggler">
<!-- ml-auto for right and mr-auto for left -->
<ul class="navbar-nav mr-auto mt-2 mt-lg-0">
<li class="nav-item active"><a class="nav-link" href="#">Home</a></li>
<li class="nav-item"><a class="nav-link" href="#">Activities</a></li>
</ul>
</div>
</nav> <!--navbar -->
</div><!--navbar wrapper-->
</header>
`
Test Home
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width", initial-scale="1.0" shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
`
Also, do not forget to add the initial stylesheet imports in the head of the HTML document as that stylesheet will play a key role in displaying the page properly. Specifying the width for the device width will allow the html document to adjust to the device width and UTF-8 specifies the character encoding to the HTML interpreter its something that all developers should get into the habit of including!

Want to have Nav-Item be same height as Nav-Bar

I am using Bootstrap 4 and trying to make a nav-item have the same height as my navbar so that when I add background-color to it it looks like a stripe through the nav-bar.
Initially the item was centered and left space on top and below. I added negative margin to get it up against the top but the same didn't work when I tried to add "margin-bottom"
I then tried fixing the height of the navbar but when I did that and clicked on the toggle to bring down the navbar items they didn't show up because the fixed height prevented it from appearing.
<body>
<nav class="navbar navbar-dark bg-dark text-center">
<div class="container">
<div class="mr-auto order-0" class= "d-flex align-items-stretch">
<a class="navbar-brand ml-auto" style="background-color:red; line-height: 58px; margin-top:-9px; padding: 0 20px 0 20px;" class="nav-item active" href="#">Matthew Krebs</a>
</div>
<a class="navbar-brand text-center" href="#"></a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive"
aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ml-auto mx-auto">
<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>
</ul>
</div>
</div>
</nav>
</body>
Here you go!
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
<title>Hello, world!</title>
</head>
<body>
<nav style="padding-top: 0px; padding-bottom: 0px;" class="navbar navbar-expand-lg navbar-light bg-light" id="navbar">
<a class="navbar-brand" href="#">Navbar</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="#">Features</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Pricing</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
</li>
</ul>
</div>
</nav>
<h1>Hello, world!</h1>
<!-- Optional JavaScript; choose one of the two! -->
<!-- Option 1: jQuery and Bootstrap Bundle (includes Popper) -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#4.5.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx" crossorigin="anonymous"></script>
<!-- Option 2: jQuery, Popper.js, and Bootstrap JS
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js#1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#4.5.3/dist/js/bootstrap.min.js" integrity="sha384-w1Q4orYjBQndcko6MimVbzY0tgp4pWB4lZ7lr30WKz0vr/aWKhXdBNmNb5D92v7s" crossorigin="anonymous"></script>
-->
<script>
document.querySelectorAll(".nav-item").forEach(item => {
item.style.height = document.getElementById("navbar").offsetHeight;
item.style.backgroundColor = 'aqua';
item.style.marginRight = '5px';
})
</script>
</body>
</html>
A few things:
I changed the inline CSS to a separate class just for the red background
added the nav-link class so that you can see the behavior of the nav-item on the top and those which are revealed upon clicking the burger menu
the navbar class had a padding which we had to overwrite to take care of the stripe look
make sure that your CSS is loaded after bootstrap, so that you can override it without using !important
working snippet below:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.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.4.1/js/bootstrap.min.js"></script>
<nav class="navbar navbar-dark bg-dark text-center">
<div class="container">
<div class="mr-auto order-0" class="d-flex align-items-stretch">
<a class="nav-item nav-link my-custom-style" href="#">Matthew Krebs</a>
</div>
<a class="navbar-brand text-center" href="#"></a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ml-auto mx-auto">
<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>
</ul>
</div>
</div>
</nav>
<style>
.navbar {
padding-top: 0;
padding-bottom: 0;
}
/* just to highlight our nav-item */
.my-custom-style {
background-color: red;
}
.nav-link {
border: 1px dotted yellow;
}
</style>
The desired effect can be achieved by simply removing the padding from the <nav> element. The easiest way to do this is to add the p-0 class to the <nav>. Bootstrap includes several margin and padding utility classes. Read about them here.
<nav class="navbar navbar-dark bg-dark text-center p-0">
<div class="container">
<div class="mr-auto order-0" class="d-flex align-items-stretch">
<a class="navbar-brand ml-auto"class="nav-item active" href="#">
Matthew Krebs
</a>
</div>
<button class="navbar-toggler" data-toggle="collapse" data-target="#navbarResponsive">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ml-auto mx-auto">
<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>
</ul>
</div>
</div>
</nav>
Codepen example.