How do I inline a div in navbar element - html

I am having some problems with my html. I am making a navbar offcanvas. Here is my code:
<nav class="navbar navbar-dark bg-dark">
<div class="container-fluid">
<a class="navbar-brand mx-2" href="#">Olau Pla Richart</a>
<button class="navbar-toggler" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasDarkNavbar" aria-controls="offcanvasDarkNavbar">
<span class="navbar-toggler-icon"></span>
</button>
<div class="offcanvas offcanvas-end text-bg-dark" tabindex="-1" id="offcanvasDarkNavbar" aria-labelledby="offcanvasDarkNavbarLabel">
<div class="offcanvas-header">
<h4 class="offcanvas-title" id="offcanvasDarkNavbarLabel">Menu</h4>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
<ul class="navbar-nav justify-content-end flex-grow-1 pe-3">
<li class="nav-item">
<h5><a class="nav-link active border-bottom bi bi-house" href="#home"> Home</a></h5>
</li>
<li class="nav-item">
<h5><a class="nav-link border-bottom bi bi-info-circle" href="#about"> About</a></h5>
</li>
<li class="nav-item">
<h5><a class="nav-link border-bottom bi bi-person-lines-fill" href="#contact"> Contact</a></h5>
</li>
<li class="nav-item">
<h5><a class="nav-link border-bottom bi bi-card-heading" href="#"> Blog</a></h5>
</li>
</ul>
</div>
</div>
</div>
<div>
<a>Test</a>
</div>
</nav>
What I am trying to do is get the Test in the same line as Olau Pla Richart. Here is what my code does at the moment:
I tried adding display: inline; and display: inline-block; but I got no change.

You need to move your div, also wrap a and that same div (now span) in a div to not get spaced because bootstrap 5 has this rule .navbar > .container-fluid { ... , justify-content: space-between}
.test {
color: white
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx" crossorigin="anonymous">
<nav class="navbar navbar-dark bg-dark">
<div class="container-fluid">
<div>
<a class="navbar-brand mx-2" href="#">Olau Pla Richart</a>
<span>
<a class="test" href="#">Test</a>
</span>
</div>
<button class="navbar-toggler" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasDarkNavbar" aria-controls="offcanvasDarkNavbar">
<span class="navbar-toggler-icon"></span>
</button>
<div class="offcanvas offcanvas-end text-bg-dark" tabindex="-1" id="offcanvasDarkNavbar" aria-labelledby="offcanvasDarkNavbarLabel">
<div class="offcanvas-header">
<h4 class="offcanvas-title" id="offcanvasDarkNavbarLabel">Menu</h4>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
<ul class="navbar-nav justify-content-end flex-grow-1 pe-3">
<li class="nav-item">
<h5><a class="nav-link active border-bottom bi bi-house" href="#home"> Home</a></h5>
</li>
<li class="nav-item">
<h5><a class="nav-link border-bottom bi bi-info-circle" href="#about"> About</a></h5>
</li>
<li class="nav-item">
<h5><a class="nav-link border-bottom bi bi-person-lines-fill" href="#contact"> Contact</a></h5>
</li>
<li class="nav-item">
<h5><a class="nav-link border-bottom bi bi-card-heading" href="#"> Blog</a></h5>
</li>
</ul>
</div>
</div>
</div>
</nav>

Try border-bottom (border-bottom: 1px solid #ccc)
details

Try adding display: flex; to your navbar class.

You do not need any additional CSS, You just need to place the a in the the proper place (after .navbar-brand), and add .navbar-text to get the correct color for .navbar-dark/.navbar-light. It will be centered between .navbar-brand and .navbar-toggler by default. You can use .me-auto to left-align it, or .ms-auto to right-align.
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx" crossorigin="anonymous">
<nav class="navbar navbar-dark bg-dark">
<div class="container-fluid">
<a class="navbar-brand mx-2" href="#">Olau Pla Richart</a>
<a class="navbar-text ms-auto me-2">Test</a>
<button class="navbar-toggler" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasDarkNavbar" aria-controls="offcanvasDarkNavbar">
<span class="navbar-toggler-icon"></span>
</button>
<div class="offcanvas offcanvas-end text-bg-dark" tabindex="-1" id="offcanvasDarkNavbar" aria-labelledby="offcanvasDarkNavbarLabel">
<div class="offcanvas-header">
<h4 class="offcanvas-title" id="offcanvasDarkNavbarLabel">Menu</h4>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
<ul class="navbar-nav justify-content-end flex-grow-1 pe-3">
<li class="nav-item">
<h5><a class="nav-link active border-bottom bi bi-house" href="#home"> Home</a></h5>
</li>
<li class="nav-item">
<h5><a class="nav-link border-bottom bi bi-info-circle" href="#about"> About</a></h5>
</li>
<li class="nav-item">
<h5><a class="nav-link border-bottom bi bi-person-lines-fill" href="#contact"> Contact</a></h5>
</li>
<li class="nav-item">
<h5><a class="nav-link border-bottom bi bi-card-heading" href="#"> Blog</a></h5>
</li>
</ul>
</div>
</div>
</div>
</nav>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.2.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-A3rJD856KowSb7dwlZdYEkO39Gagi7vIsF0jrRAoQmDKKtQBHUuLZ9AsSv4jD4Xa" crossorigin="anonymous"></script>

Related

Bootstrap 5 navigating from menu to respective section on click hides section title

I made a single landing page using bootstrap5. Created a navbar a some section.I give the id to the section same as href link in navbar . It redirect to that targeted section as expected but it navbar hides it titleIt navigates to our tour section but hides its section title.
<header class="fixed-top">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container text-center">
<a class="navbar-brand text-center d-flex flex-cloumn" href="#">
<img
src="./Images/logo.png"
alt=""
width="80"
height="50"
class="d-inline-block"
/>
</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 mt-2 ms-auto mb-2 mb-lg-0">
<li class="nav-item">
<a
class="nav-link active"
aria-current="page"
href="#"
>Discover Europe</a
>
</li>
<li class="nav-item">
<a class="nav-link" href="#ourtours"
>Our tours</a
>
</li>
<li class="nav-item">
<a class="nav-link" href="#customizedtour"> Customized tour</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#whychooseus">Why Choose Us?</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#aboutus">About Us</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
You have <header class="fixed-top"> - fixed positioning does not account for elements below/behind. Judging by your screenshot that seems to be an issue. Change fixed-top to sticky-top and it should work just fine.
I made a few snippets which should help.
Version 1 - fixed-top first and the second section is behind the header.
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
<header class="fixed-top">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container text-center">
<a class="navbar-brand text-center d-flex flex-cloumn" href="#">
<img src="./Images/logo.png" alt="" width="80" height="50" class="d-inline-block" />
</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 mt-2 ms-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Discover Europe</a
>
</li>
<li class="nav-item">
<a class="nav-link" href="#ourtours"
>Our tours</a
>
</li>
<li class="nav-item">
<a class="nav-link" href="#customizedtour"> Customized tour</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#whychooseus">Why Choose Us?</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#aboutus">About Us</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
<section id="ourtours">
<h1>our tours</h1>
</section>
<section id="customizedtour">
<h1>customized tours</h1>
</section>
<section id="ourtours">
<h1>why choose us</h1>
</section>
Version 2 - sticky-top first section is directly below header.
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
<header class="sticky-top">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container text-center">
<a class="navbar-brand text-center d-flex flex-cloumn" href="#">
<img src="./Images/logo.png" alt="" width="80" height="50" class="d-inline-block" />
</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 mt-2 ms-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Discover Europe</a
>
</li>
<li class="nav-item">
<a class="nav-link" href="#ourtours"
>Our tours</a
>
</li>
<li class="nav-item">
<a class="nav-link" href="#customizedtour"> Customized tour</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#whychooseus">Why Choose Us?</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#aboutus">About Us</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
<section id="ourtours">
<h1>our tours</h1>
</section>
<section id="customizedtour">
<h1>customized tours</h1>
</section>
<section id="ourtours">
<h1>why choose us</h1>
</section>

Trying to center navbar links bootstrap 4 [duplicate]

This question already has an answer here:
Center Navbar links without brand pushing it to the right in Bootstrap 4?
(1 answer)
Closed 3 years ago.
Im Trying to center my links right under the h1, but nothing works. Here's what i have right now, i would love any help or pointers!
This is my h1-tag
<div class="container-fluid p-5 bg-success header-body text-center">
<h1 id="high-credit-top-text">
<a class="text-white" style="font-family: 'Lexend Deca', sans-serif;" href="hogkostnadskredit.php">Playaround.se</a>
</h1>
<nav class="navbar navbar-expand-lg navbar-light bg-success">
<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">
<div class="container justify-content-center">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link text-white" href="playaround.php"><i class="fas fa-home"></i></a>
</li>
<li class="nav-item">
<a class="nav-link text-white" href="nyheter.php">Nyheter</a>
</li>
<li class="nav-item">
<a class="nav-link text-white" href="information.php">Infomartion</a>
</li>
</ul>
</div>
</div>
</nav>
If you are trying to center the .nav-item links horizontally, then add the bootstrap class justify-content-center to the ul tag with class navbar-nav
<ul class="navbar-nav justify-content-center">
<li class="nav-item active">
<a class="nav-link text-white" href="playaround.php"><i class="fas fa-home"></i></a>
</li>
<li class="nav-item">
<a class="nav-link text-white" href="nyheter.php">Nyheter</a>
</li>
<li class="nav-item">
<a class="nav-link text-white" href="information.php">Infomartion</a>
</li>
</ul>
Example
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<div class="container-fluid p-5 bg-success header-body text-center">
<h1 id="high-credit-top-text">
<a class="text-white" style="font-family: 'Lexend Deca', sans-serif;" href="hogkostnadskredit.php">Playaround.se</a>
</h1>
</div>
<nav class="navbar navbar-expand-lg navbar-light bg-success">
<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">
<div class="container justify-content-center">
<ul class="navbar-nav justify-content-center">
<li class="nav-item active">
<a class="nav-link text-white" href="playaround.php"><i class="fas fa-home"></i></a>
</li>
<li class="nav-item">
<a class="nav-link text-white" href="nyheter.php">Nyheter</a>
</li>
<li class="nav-item">
<a class="nav-link text-white" href="information.php">Infomartion</a>
</li>
</ul>
</div>
</div>
</nav>

how to make some child items 50% wide and side by side in flex-direction column container?

I using bootstrap 4 .navbar-nav.
Here is a full live demo on codeply https://www.codeply.com/go/Zib61kYY2M
When the .navbar-nav goes into mobile collapsed mode on the set breakpoint.
These styles below are applied, and creates a nice stacked list of the navbar buttons.
display: flex;
flex-direction: column;
But I need to control the width of the last two child .nav-item. And I need the items to appear side by side.
Is this possible with flex?
This currently how the nav looks...
This is how I want the last two items to look...
I've added 2 classes the last 2 items called .nav-account, so I just need to set some css like this...
.nav-account {
width: 50%;
...
}
So make the last 2 items 50% wide and next to each other.
Full code below and here https://www.codeply.com/go/Zib61kYY2M
<ul class="navbar-nav flex-lg-grow-1 text-center text-lg-right">
<li class="nav-item active">
<a class="nav-link" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Products</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">FAQ's</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact</a>
</li>
<li class="nav-item nav-account ml-lg-auto">
<a class="nav-link" href="https://dev.thesweetpeople.co/wp-login.php?redirect_to=https%3A%2F%2Fdev.thesweetpeople.co%2Fprofile">Log in</a>
</li>
<li class="nav-item nav-account">
<a class="nav-link" href="/register"><i class="fas fa-fw fa-user-plus color-sweets"></i> Register</a>
</li>
</ul>
You can try the following:
Add flex-wrap flex-row classes to your ul (this sets the flex-direction always as row and set flex-wrap)
Add col-12 col-lg-auto to your nav-items expect the last two (sets 100% flex-basis in mobile view)
Add col-6 col-lg-auto to the last two nav-items (sets 50% flex-basis for the last two items in mobile view)
See demo below:
.navbar {
opacity: 1;
transition: opacity 0.5s ease;
}
.navbar-hide {
pointer-events: none;
opacity: 0;
}
.nav-item {
border: 1px solid red;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" />
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.1/css/all.css" />
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script>
<nav class="navbar navbar-expand-lg navbar-dark fixed-top bg-dark">
<a class="navbar-brand" href="#">Flex direction</a>
<button class="navbar-toggler" type="button" 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 flex-lg-grow-1 text-center text-lg-right flex-wrap flex-row">
<li class="nav-item col-12 col-lg-auto active">
<a class="nav-link" href="#">Home</a>
</li>
<li class="nav-item col-12 col-lg-auto">
<a class="nav-link" href="#">Products</a>
</li>
<li class="nav-item col-12 col-lg-auto">
<a class="nav-link" href="#">About</a>
</li>
<li class="nav-item col-12 col-lg-auto">
<a class="nav-link" href="#">FAQ's</a>
</li>
<li class="nav-item col-12 col-lg-auto">
<a class="nav-link" href="#">Contact</a>
</li>
<li class="nav-item nav-account ml-lg-auto col-6 col-lg-auto">
<a class="nav-link" href="https://dev.thesweetpeople.co/wp-login.php?redirect_to=https%3A%2F%2Fdev.thesweetpeople.co%2Fprofile">Log in</a>
</li>
<li class="nav-item nav-account col-6 col-lg-auto">
<a class="nav-link" href="/register"><i class="fas fa-fw fa-user-plus color-sweets"></i> Register</a>
</li>
</ul>
</div>
</nav>
<main role="main" class="container">
<div class="jumbotron">
<h1>Flex direction</h1>
<p class="lead">My question, in mobile mode, is it possible to make the the <strong>register</strong> and <strong>login</strong> buttons 50% wide and side by side using flex?</p>
<a class="btn btn-lg btn-primary" href="https://getbootstrap.com/docs/4.3/utilities/flex/" role="button">View flex docs ยป</a>
</div>
</main>
One solution can be wrapping the last two <li> items inside next element:
<div class="ml-lg-auto d-inline-flex">
...
</div>
And then add classes w-50 to both of they.
Example:
<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.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<nav class="navbar navbar-expand-lg navbar-dark fixed-top bg-dark">
<a class="navbar-brand" href="#">Flex direction</a>
<button class="navbar-toggler" type="button" 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 flex-lg-grow-1 text-center text-lg-right">
<li class="nav-item active border">
<a class="nav-link" href="#">Home</a>
</li>
<li class="nav-item border">
<a class="nav-link" href="#">Products</a>
</li>
<li class="nav-item border">
<a class="nav-link" href="#">About</a>
</li>
<li class="nav-item border">
<a class="nav-link" href="#">FAQ's</a>
</li>
<li class="nav-item border">
<a class="nav-link" href="#">Contact</a>
</li>
<div class="ml-lg-auto d-inline-flex">
<li class="nav-item nav-account w-50 border">
<a class="nav-link" href="#">Log in</a>
</li>
<li class="nav-item nav-account w-50 border">
<a class="nav-link" href="/register">
<i class="fas fa-fw fa-user-plus color-sweets"></i>
Register
</a>
</li>
</div>
</ul>
</div>
</nav>
Here is another version, that use nested <li> and <ul> items to don't fall on usage of invalid markup as mentioned on the commentaries:
Alternative version:
.custom-ul {
list-style:none;
padding: 0px;
margin: 0px;
}
<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.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<nav class="navbar navbar-expand-lg navbar-dark fixed-top bg-dark">
<a class="navbar-brand" href="#">Flex direction</a>
<button class="navbar-toggler" type="button" 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 flex-lg-grow-1 text-center text-lg-right">
<li class="nav-item active border">
<a class="nav-link" href="#">Home</a>
</li>
<li class="nav-item border">
<a class="nav-link" href="#">Products</a>
</li>
<li class="nav-item border">
<a class="nav-link" href="#">About</a>
</li>
<li class="nav-item border">
<a class="nav-link" href="#">FAQ's</a>
</li>
<li class="nav-item border">
<a class="nav-link" href="#">Contact</a>
</li>
<li class="ml-lg-auto">
<ul class="custom-ul d-flex">
<li class="nav-item nav-account w-50 border">
<a class="nav-link" href="#">Log in</a>
</li>
<li class="nav-item nav-account w-50 border">
<a class="nav-link" href="/register">
<i class="fas fa-fw fa-user-plus color-sweets"></i>
Register
</a>
</li>
</ul>
</li>
</ul>
</div>
</nav>

Why won't the navbar collapse/expand when I click the icon?

I'm using bootstrap for my navbar to have a list of links collapse and grow when clicking on the icon, but I can't seem to get it to work. I think I have all of the ids matching but something must be a miss.
<nav class="navbar navbar-expand-lg bg-dark navbar-dark d-flex" style="background-color:#7E0B2A !important;">
<!-- Logo -->
<a>
<img src="images/scc1logo3.jpg" class="d-none d-lg-block" style="max-height:80px; max-width:80px;">
</a>
<div class="d-lg-none d-block" style="color:white; font-size: 1.3rem;">
Company Name
</div>
<!-- Toggler/collapsibe Button -->
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsibleNavbar">
<span class="navbar-toggler-icon"></span>
</button>
<!-- Navbar links -->
<div class="collapse navbar-collapse align-items-left justify-content-between" id="collapsibleNavbar">
<ul class="navbar-nav text-left d-flex justify-content-center">
<li class="nav-item pl-lg-1">
<a class="nav-link" style="color:white;" href="index.html">Home</a>
</li>
<li class="nav-item pl-lg-1">
<a class="nav-link" style="color:white;" href="about.html">About SCC</a>
</li>
<li class="nav-item pl-lg-1">
<a class="nav-link" style="color:white;" href="Project.html">Projects</a>
</li>
<li class="nav-item pl-lg-1">
<a class="nav-link" style="color:white;" href="Collaborators.html">Collaborators</a>
</li>
<li class="nav-item pl-lg-1">
<a class="nav-link" style="color:white;">Calender</a>
</li>
<li class="nav-item pl-lg-1">
<a class="nav-link" style="color:white;">Contact Us</a>
</li>
<li class="nav-item pl-lg-1 d-block d-lg-none">
<a class="nav-link" style="color:white;">Donate</a>
</li>
</ul>
<div class="d-lg-block d-none">
<a class="nav-link" style="color:white;">Donate</a>
</div>
</div>
</nav>
I am not sure what is the problem? Are you including bootstrap libraries?
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script>
</head>
<body>
<nav class="navbar navbar-expand-lg bg-dark navbar-dark d-flex" style="background-color:#7E0B2A !important;">
<!-- Logo -->
<a>
<img src="images/scc1logo3.jpg" class="d-none d-lg-block" style="max-height:80px; max-width:80px;">
</a>
<div class="d-lg-none d-block" style="color:white; font-size: 1.3rem;">
Company Name
</div>
<!-- Toggler/collapsibe Button -->
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsibleNavbar">
<span class="navbar-toggler-icon"></span>
</button>
<!-- Navbar links -->
<div class="collapse navbar-collapse align-items-left justify-content-between" id="collapsibleNavbar">
<ul class="navbar-nav text-left d-flex justify-content-center">
<li class="nav-item pl-lg-1">
<a class="nav-link" style="color:white;" href="index.html">Home</a>
</li>
<li class="nav-item pl-lg-1">
<a class="nav-link" style="color:white;" href="about.html">About SCC</a>
</li>
<li class="nav-item pl-lg-1">
<a class="nav-link" style="color:white;" href="Project.html">Projects</a>
</li>
<li class="nav-item pl-lg-1">
<a class="nav-link" style="color:white;" href="Collaborators.html">Collaborators</a>
</li>
<li class="nav-item pl-lg-1">
<a class="nav-link" style="color:white;">Calender</a>
</li>
<li class="nav-item pl-lg-1">
<a class="nav-link" style="color:white;">Contact Us</a>
</li>
<li class="nav-item pl-lg-1 d-block d-lg-none">
<a class="nav-link" style="color:white;">Donate</a>
</li>
</ul>
<div class="d-lg-block d-none">
<a class="nav-link" style="color:white;">Donate</a>
</div>
</div>
</nav>
</body>

Bootstrap 4 Navbar align content left, center and right [duplicate]

This question already has answers here:
Bootstrap NavBar with left, center or right aligned items
(14 answers)
Center an element in Bootstrap Navbar
(10 answers)
Closed 4 years ago.
I need to achieve the brand logo in left, menu items to be center and couple of buttons in the right. I have tried using the flexbox approach but the center items does not align well. and also the brand logo has a wide space with a clickable link.
JS Fiddle
<nav class="navbar navbar-light navbar-expand-md bg-faded justify-content-center">
<div class="container">
<img src="assets/logo/" alt="logo">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsingNavbar3">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse w-100 ml-auto" id="collapsingNavbar3">
<ul class="navbar-nav w-100 justify-content-center">
<li class="nav-item active">
<a class="nav-link" href="#">How it works</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Become a tutor</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Pricing</a>
</li>
</ul>
<ul class="nav navbar-nav ml-auto w-100 justify-content-end">
<li class="nav-item">
<a class="btn btn-link" href="#">Sign In</a>
</li>
<li class="nav-item">
<a class="btn btn-primary" href="#">Sign Up</a>
</li>
</ul>
</div>
</div>
</nav>
Answering my own question few months later.
<nav class="navbar navbar-light navbar-expand-md bg-white justify-content-center main--navigation dark-header">
<a href="#" class="navbar-brand d-flex w-50 mr-auto">
<img src="assets/images/logo-header.svg" class="navigation__logo" alt="Logo" />
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsingNavbar">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse w-100" id="collapsingNavbar">
<ul class="navbar-nav w-100 justify-content-center">
<li class="nav-item active">
<a class="nav-link" href="#">Browse</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">How it works</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Become a tutor</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Prices</a>
</li>
</ul>
<ul class="nav navbar-nav ml-auto w-100 justify-content-end">
<li class="nav-item dropdown no-arrow mx-1 nav-link px-0">
<button id="bookmarksDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" type="button" class="btn btn-outline-secondary btn-outlined" data-original-title="Bookmarks"><img src="assets/icons/bookmark-header-dark.svg"></button>
<div class="dropdown-list dropdown-menu dropdown-menu-right" aria-labelledby="alertsDropdown">
<h6 class="dropdown-header">
Bookmarks
</h6>
</div>
</li>
<li class="nav-item dropdown no-arrow mx-1 nav-link px-0">
<button id="messagesDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" type="button" class="btn btn-outline-secondary btn-outlined" data-original-title="Notifications"><img src="assets/icons/bell-header-dark.svg"></button>
<div class="dropdown-list dropdown-menu dropdown-menu-right" aria-labelledby="notificationsDropdown">
<h6 class="dropdown-header">
You do not have any notifications yet
</h6>
</div>
</li>
<li class="nav-item dropdown no-arrow mx-1 ml-3 mr-0 nav-link px-0">
<a class="nav-link dropdown-toggle pr-0" href="#" id="userDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<div class="header__profile__title d-inline-block text-right align-middle">
<span class="mr-2 d-none d-block header__profile__name">Aaron Alexander</span>
<span class="mr-2 d-none d-block header__profile__role">Student</span>
</div>
<div class="header__profile d-inline-block">
<img class="img-profile rounded" src="assets/images/andrew-franklin.jpeg" alt="Aaron Alexander">
</div>
</a>
<div class="dropdown-menu dropdown-menu-right shadow animated--grow-in" aria-labelledby="userDropdown">
<a class="dropdown-item" href="#">
<i class="fas fa-user fa-sm fa-fw mr-2"></i>
Profile
</a>
<a class="dropdown-item" href="#">
<i class="fas fa-cogs fa-sm fa-fw mr-2"></i>
Settings
</a>
<a class="dropdown-item" href="#">
<i class="fas fa-list fa-sm fa-fw mr-2"></i>
Activity Log
</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#logoutModal">
<i class="fas fa-sign-out-alt fa-sm fa-fw mr-2 text-gray-400"></i>
Logout
</a>
</div>
</li>
</ul>
</div>
</nav>
That container div you added after the nav makes you loose the flexbox attributes.
You also set the logo with the class "w-100" which takes all possible width.
I removed those and got a nicely aligned navbar.
<nav class="navbar navbar-light navbar-expand-md bg-faded justify-content-center align-items-center">
<img src="assets/logo/" alt="logo">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsingNavbar3">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse w-100 ml-auto" id="collapsingNavbar3">
<ul class="navbar-nav w-100 justify-content-center">
<li class="nav-item active">
<a class="nav-link" href="#">How it works</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Become a tutor</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Pricing</a>
</li>
</ul>
<ul class="nav navbar-nav ml-auto w-100 justify-content-end">
<li class="nav-item">
<a class="btn btn-link" href="#">Sign In</a>
</li>
<li class="nav-item">
<a class="btn btn-primary" href="#">Sign Up</a>
</li>
</ul>
</div>
</nav>
Here's a fiddle with the results.
here is my working example.
You just need to put all content into single div in order to Justify content with bootstrap classes. Also, I am using navbar-brand and making them show hide depending on screen resolution. You can do that with js which might be smoother once the page loads completely.
#media only screen and (max-width: 991px) {
.logo {
display: flex;
}
.collapse .navbar-brand {
display: none
}
}
#media only screen and (min-width: 992px) {
.logo {
display: none;
}
.collapse .navbar-brand {
display: none;
}
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" />
<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>
<nav class="navbar navbar-expand-lg navbar-light bg-light d-flex ">
<a class="navbar-brand logo" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse justify-content-between" id="navbarSupportedContent">
<a class="navbar-brand" href="#">Navbar</a>
<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="#">Link</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</div>
</nav>