Trying to center navbar links bootstrap 4 [duplicate] - html

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>

Related

I am working with Bootstrap 5.2 and my mobile menu will not shut when toggled I would appreciate another set of eyes on the code. Thanks in advance

<body style="background-image: url('/img/smush.png');background-size:cover;background-repeat:no-repeat">
<div class="container">
<header class="pt-2">
<nav class="navbar navbar-expand-lg bg-none fixed-top">
<div class="container-fluid">
<a class="navbar-brand" href="#">Slightly Sophisticated</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 bg-none p-2 d-flex flex-column justify-content-end" id="navbarSupportedContent">
<ul class="nav">
<li class="nav-item">
<a class="nav-link active text-dark" aria-current="page" href="#services">Services</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" href="#mission">About</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" href="#work">Work</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" href="#testimonials">Testimonials</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" href="#contact">Contact</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
I was expecting the toggle to work correctly on mobile. Not sure why it is not working right now, I feel like i looked through it thoroughly but its obviously not the case if i am asking the question here lol

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>

How can I move the "ul" block of navbar to the right without affecting the toggle button functionality of responsiveness in the navbar?

I am using bootstrap NavBar ..
When trying to move the ul block to the right it disables the toggle button responsiveness ...
<head>
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
</head>
<nav class="navbar navbar-expand-lg navbar-light bg-dark">
<div class="container-fluid">
<a class="navbar-brand nav-text text-white" href="#">Rehan's Thoughts</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-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">
<a class="nav-link text-white active" aria-current="page" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link text-white" href="#">About</a>
</li>
<li class="nav-item">
<a class="nav-link text-white" href="#">Contact</a>
</li>
<li class="nav-item">
<a class="nav-link text-white disabled">Blog</a>
</li>
</ul>
</div>
</div>
</nav>
Add w-100(width: 100%;) to your ul element and also add justify-content-end or (justify-content: right;)
<head>
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
</head>
<nav class="navbar navbar-expand-lg navbar-light bg-dark">
<div class="container-fluid">
<a class="navbar-brand nav-text text-white" href="#">Rehan's Thoughts</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-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 w-100 justify-content-end">
<li class="nav-item">
<a class="nav-link text-white active" aria-current="page" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link text-white" href="#">About</a>
</li>
<li class="nav-item">
<a class="nav-link text-white" href="#">Contact</a>
</li>
<li class="nav-item">
<a class="nav-link text-white disabled">Blog</a>
</li>
</ul>
</div>
</div>
</nav>

Navbar items alingment for bootstrap 5

I am sticking to this problem for such a long time. Please help me to fix it... I really tried various ways but none of them is actually working.
I want my login button at the end of my navbar(right side) and when I decrease the screen size i wanted it to be appear on the left side of the burgger menu
Here is my code -
<header class="header">
<nav class="navbar navbar-expand-md navbar-light bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="#">
<img src="image/logo.png" alt="" width="150px" height="35px">
</a>
<div class="login-nav ms-auto mb-2 me-2 ">
<ul class="navbar-nav login">
<li class="navbar-item login-item">
<a class="nav-link active" aria-current="page" href="#">Login</a>
</li>
</ul>
</div>
<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 ">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
I want them like these pictures :
enter image description here
enter image description here
This is a workaround. There are two login links.
<header class="header">
<nav class="navbar navbar-expand-md navbar-light bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="#">
<img src="image/logo.png" alt="" width="150px" height="35px">
</a>
<div class="mb-2 me-2 d-block d-md-none">
<ul class="navbar-nav login">
<li class="navbar-item login-item">
<a class="nav-link active" aria-current="page" href="#">Login</a>
</li>
</ul>
</div>
<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 ">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
</li>
</ul>
</div>
<div class="mb-2 me-2 d-none d-md-block">
<ul class="navbar-nav login">
<li class="navbar-item login-item">
<a class="nav-link active" aria-current="page" href="#">Login</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
<header class="header">
<nav class="navbar navbar-expand-md navbar-light bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="#">
<img src="image/logo.png" alt="" width="150px" height="35px">
</a>
<div class="navbar-nav ms-auto me-2 d-block d-md-none">
<ul class="navbar-nav">
<li class="nav-item ">
<a class="nav-link active" aria-current="page" href="#">Login</a>
</li>
</ul>
</div>
<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 justify-content-between" id="navbarSupportedContent">
<ul class="navbar-nav ms-auto mb-2 ">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
</li>
</ul>
</div>
<div class="navbar-nav ms-auto me-2 d-none d-md-block">
<ul class="navbar-nav">
<li class="nav-item ">
<a class="nav-link active" aria-current="page" href="#">Login</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
This is working as expected :) This for the idea Yasin

Bootstrap hamburger menu not collapsing

I'm building a site in Bootstrap and my hamburger menu is not collapsing. Here is the HTML code:
<section>
<div class="container-fluid main-banner">
<div class="row">
<div class="col-12">
<nav class="navbar navbar-expand-lg navbar-light bg-light main-nav">
<a class="navbar-brand" href="#"><img src="images/logo.png"></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="custom-toggler" role="button" ><i class="fa fa-bars" aria-hidden="true"></i></span>
</button>
<div class="collapse navbar-collapse">
<ul class="navbar-nav ml-auto">
<li class="nav-item"> <a class="nav-link" href="#">Home</a> </li>
<li class="nav-item"> <a class="nav-link" href="#">Our Culture</a> </li>
<li class="nav-item"> <a class="nav-link" href="#">Our Curriculum</a> </li>
<li class="nav-item"> <a class="nav-link" href="#">News</a> </li>
<li class="nav-item"> <a class="nav-link see-through-button" href="#">Apply</a> </li>
</ul>
</div>
</nav>
</div>
</div>
<div class="row main-banner-text">
<div class="col-lg-6">
<h1>Know Your Greatness.</h1>
<h3>Develop your passion and align your education with real world needs.</h3>
<div class="top-padding">Your future starts now</div>
</div>
<div class="col-lg-6"></div>
</div>
</div>
</section>
I would appreicate any feedback as I am pretty much stumped at this point. I've tried looking on other threads but haven't found anything yet.
You need to call id used in data-target="#navbarSupportedContent" for show hide navbar div please check below code
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.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.5.0/js/bootstrap.min.js"></script><section>
<div class="container-fluid main-banner">
<div class="row">
<div class="col-12">
<nav class="navbar navbar-expand-lg navbar-light bg-light main-nav">
<a class="navbar-brand" href="#"><img src="images/logo.png"></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="custom-toggler" role="button" ><i class="fa fa-bars" aria-hidden="true"></i></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ml-auto">
<li class="nav-item"> <a class="nav-link" href="#">Home</a> </li>
<li class="nav-item"> <a class="nav-link" href="#">Our Culture</a> </li>
<li class="nav-item"> <a class="nav-link" href="#">Our Curriculum</a> </li>
<li class="nav-item"> <a class="nav-link" href="#">News</a> </li>
<li class="nav-item"> <a class="nav-link see-through-button" href="#">Apply</a> </li>
</ul>
</div>
</nav>
</div>
</div>
<div class="row main-banner-text">
<div class="col-lg-6">
<h1>Know Your Greatness.</h1>
<h3>Develop your passion and align your education with real world needs.</h3>
<div class="top-padding">Your future starts now</div>
</div>
<div class="col-lg-6"></div>
</div>
</div>
</section>