I have a navbar in bootstrap that has the links and a logo in the center. The navbar stretches to fit the logo image, I'd rather have the logo overlap the navbar. Here is my code, I actually used a base someone already made yet it still doesn't work.
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="navbar-collapse collapse w-100 dual-collapse2 order-1 order-md-0">
<ul class="navbar-nav ml-auto text-center">
<li class="nav-item active">
<a class="nav-link" href="#">Link</a>
</li>
</ul>
</div>
<div class="mx-auto my-2 order-0 order-md-1 position-relative">
<a class="mx-auto" href="#">
<img src="http://placehold.it/120/ccff00" class="rounded-circle" height="120" width="120">
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".dual-collapse2">
<span class="navbar-toggler-icon"></span>
</button>
</div>
<div class="navbar-collapse collapse w-100 dual-collapse2 order-2 order-md-2">
<ul class="navbar-nav mr-auto text-center">
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
</ul>
</div>
</nav>
CSS
#media (min-width: 992px) {
.navbar {
height:50px;
}
}
Related
I have tried using flex property and justify content but that doesn't work as well. I tried the below mentioned code.
the aim is to make a website with a logo on top and navbar right below like shown below
how the site looks like as of now
<header class="top-part">
<div class="logo">
<img class="logo" src="images/logo.png" height=100px width="237px" >
</div>
<nav class="navbar navbar-expand-lg navbar-light bg-light ">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNavDropdown">
<ul class="navbar-nav ">
<li >
<a class="nav-link" id="home"href="#">link 1</a>
</li>
<li class="nav-item">
<a class="nav-link" id="cart" href="#">link 2</a>
</li>
<li class="nav-item">
<a class="nav-link" id="contact"href="#">link 3</a>
</li>
</ul>
</div>
</nav>
</header>
</head>
css :
#media screen and (min-width:777px){
.nav-link {
padding:18px 0;
min-width:120px;
}
.navbar {
padding: 0
}
}
.header{
position:sticky ;
top: 0;
}
I'd recommend doing some research and practicing with some basic HTML/CSS, so you understand the basics and know what everything does.
For this specific example you should look into 'flexbox'!
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<header class="d-flex flex-column align-items-center">
<img style="width: 100px;" src="https://images.unsplash.com/photo-1605666807892-8c11d020bede?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTJ8fGJhbmFuYXxlbnwwfHwwfHw%3D&w=1000&q=80" alt="">
<nav class="w-100 d-flex bg-light">
<a class="p-2 bd-highlight text-black-50 text-decoration-none" href="">link 1</a>
<a class="p-2 bd-highlight text-black-50 text-decoration-none" href="">link 2</a>
<a class="p-2 bd-highlight text-black-50 text-decoration-none" href="">link 3</a>
</nav>
</header>
header {
width: 100%;
text-align: center;
}
a:first-of-type{
float: left;
}
a:last-of-type{
float: right;
}
<header>
<img style="width: 100px;" src="https://images.unsplash.com/photo-1605666807892-8c11d020bede?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTJ8fGJhbmFuYXxlbnwwfHwwfHw%3D&w=1000&q=80" alt="">
<nav>
link 1
link 2
link 3
</nav>
</header>
Here is one method:
Add d-flex, flex-row, and justify-content-center to your parent div containing the logo.
You can add the same to your parent div for the links (ul and li's)
Your links are left aligned, so you can add "text-center" to classes of your <ul> element.
It would look like this:
<header class="top-part">
<div class="logo d-flex flex-row justify-content-center">
<img class="logo" src="images/logo.png" height=100px width="237px" >
</div>
<nav class="navbar navbar-expand-lg navbar-light bg-light ">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse d-flex flex-row justify-content-center" id="navbarNavDropdown">
<ul class="navbar-nav text-center">
<li>
<a class="nav-link" id="home" href="#">link 1</a>
</li>
<li class="nav-item">
<a class="nav-link" id="cart" href="#">link 2</a>
</li>
<li class="nav-item">
<a class="nav-link" id="contact"href="#">link 3</a>
</li>
</ul>
</div>
</nav>
</header>
Also just a note, I see your code above is ending with </head>. Make sure you are not putting this code in the <head> of your site, but the <body> :)
There was a problem with extra padding in the navbar after the site icon. Initially, the idea was to place links that are located to the left of the icon closer to the left edge using me-3, but then the icon of the site is shifted to the right, which I basically don’t need.Therefore, I have a question. Is it possible to make the same indents from the site icon and links without shifting this icon from the center or how to remove the indent between the icon and links on the right side of the navbar.
<nav class="navbar navbar-expand-lg navbar-dark fixed-top" id="scroll">
<div class="container-fluid">
<div class="collapse navbar-collapse order-1 order-lg-0 dual-collapse2" id="navbarNavAltMarkup">
<ul class="navbar-nav ms-auto">
<li class="nav-item mx-auto">
<a class="nav-link" aria-current="page" href="#articles">기사들</a>
</li>
<li class="nav-item mx-auto">
<a class="nav-link" aria-current="page" href="#mission">우리의 임무</a>
</li>
</ul>
</div>
<a class="navbar-brand order-0" href="#">
<img src="img/marslogo.png" alt="" width="30" height="30">
</a>
<div>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
</div>
<div class="collapse navbar-collapse order-3 dual-collapse2" id="navbarNavAltMarkup"
>
<ul class="navbar-nav">
<li class="nav-item mx-auto">
<a class="nav-link" aria-current="page" href="#">사진들</a>
</li>
<li class="nav-item mx-auto">
<a class="nav-link" aria-current="page" href="#">문의하기</a>
</li>
</ul>
</div>
</div>
</nav>
I'm creating a responsive website using Bootstrap 4. In desktop, things look good. However, in mobile, my logo stays in the center and the menu stays in the left. Here's my codepen.
This is what I need to achieve:
This is what I'm getting:
I am using this code according to Bootstrap's documentation.
This is my Navbar's code:
<nav class="navbar navbar-expand-lg nl-navbar navbar-light">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-
target="#navbarTogglerDemo02">
<span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand" href="service-main-landing.html">
<img src="images/logo-header.svg" alt="Logo Reebit" class="col-lg-7 col-md-4
col-sm-7 col-7"/>
</a>
<div class="collapse navbar-collapse" id="navbarTogglerDemo02">
<ul class="navbar-nav ml-auto">
<li class="nav-item active">
<a class="nav-link mr-3" href="#">Contactar un profesional</a>
</li>
<li class="nav-item active">
<a class="nav-link mr-4" href="#">Registrarme</a>
</li>
<li class="nav-item active">
<a class="nav-link mr-4" href="#">Iniciar sesión</a>
</li>
<button class="btn my-2 my-sm-0 nl-btn-nav-secondary" type="button" data-
toggle="modal" data-target="#registrationModal"
id="landingRegistrationNavBtn">Publicar servicio</button>
</ul>
</div>
</nav>
Switch your navbar-toggler position with navbar-brand.
<a class="navbar-brand" href="#">
<img src="https://via.placeholder.com/150" class="col-lg-7 col-md-4 col-sm-7 col-7">
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarTogglerDemo02">
<span class="navbar-toggler-icon"></span>
</button>
Additional: Seems like you misunderstood Bootstrap's grid system. col should be direct child of row like this:
<div class="row">
<div class="col">
</div>
<div class="col">
</div>
</div>
I am having an issue with my centered logo on bootstrap navbar menu; I put the logo in the center of the navbar; it is working fine on desktop but when I resize the page to a smaller device, the logo, because of the presence of the Hamburger menu button on the right and its relatively pixels used, becomes out of center towards to the left.
How can I make sure that on devices with smaller screens the logo remains centered?
<nav class="navbar navbar-expand-xl navbar-toggleable-md navbar-light bg-white" id="nav1">
<div class="navbar-collapse collapse w-100 order-1 dual-collapse2">
<ul class="navbar-nav mx-auto">
<li class="nav-item home">
<a class="nav-link" href="#">HOME <span class="sr-only">(current)</span> </li>
<li class="nav-item"> <a class="nav-link" href="#">OUR WEDDINGS </li>
</ul>
</div>
<div class="mx-auto order-0 order-xl-2">
<a class="navbar-brand mx-auto" href="/"><img src="Imagine/00 Top Logo 2021.png" alt="Logo 2021" width="275" height="127"></a></div>
<div class="navbar-collapse collapse w-100 order-3 dual-collapse2">
<ul class="navbar-nav mx-auto">
<li class="nav-item">
<li class="nav-item"> <a class="nav-link" href="#">LEGALITIES </li>
</ul>
</div>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".dual-collapse2">
<span class="navbar-toggler-icon"></span>
</button>
</nav>
Foreword
Before we go into the solution, one thing to note is that if this solution is implemented and the window is not wide enough to fit both the logo and the toggler without overlapping, they will do just that -- overlap.
Solution
1. Styles
You can do that using transform and position: absolute:
.navbar-brand {
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
position: absolute;
}
/* to place the toggler above the logo, in case they overlap */
.navbar-toggler: {
z-index: 10;
}
2. HTML
There are also some issues in the HTML. The big one is missing closing tags for <a class="nav-link">. See this jsfiddle version and check the HTML textarea for where the linter highlights issues. Also, the sr-only class is for screen readers so you want to include it for each link and make sure the text content matches the link itself -- see this answer for a great explanation of that.
Here's a refactored version of the HTML:
<nav class="navbar navbar-expand-xl navbar-toggleable-md navbar-light bg-white" id="nav1">
<div class="navbar-collapse collapse w-100 order-1 dual-collapse2">
<ul class="navbar-nav mx-auto">
<li class="nav-item home">
<a class="nav-link" href="https://www.weddinginsicily.co.uk/">
HOME
<span class="sr-only">Home</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://www.weddinginsicily.co.uk/wedding_sicily_our_weddings.html">
OUR WEDDINGS
<span class="sr-only">Our Weddings</span>
</a>
</li>
</ul>
</div>
<div class="mx-auto order-0 order-xl-2 navbar-brand-container">
<a class="navbar-brand mx-auto" href="/">
<img src="Imagine/00 Top Logo 2021.png" alt="Logo 2021" width="275" height="127">
</a>
</div>
<div class="navbar-collapse collapse w-100 order-3 dual-collapse2">
<ul class="navbar-nav mx-auto">
<li class="nav-item">
<a class="nav-link" href="https://www.weddinginsicily.co.uk/wedding_sicily_legalities.html">
LEGALITIES
<span class="sr-only">Legalities</span>
</a>
</li>
</ul>
</div>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".dual-collapse2">
<span class="navbar-toggler-icon"></span>
</button>
</nav>
3. Demo
See this jsfiddle demo for the complete working solution.
Hope that helps!
Add position: absolute in .navbar-toggler. See if it helps you:
https://jsfiddle.net/omk9pg58/
I am using bootstrap 4 to make an application, in which i have two navbars and both needs to be fixed at top in which the second navbar needs to hide while scrolling.
Html:
Navbar 1:
<nav class="navbar fixed-top navbar-expand-lg navbar-light bg-custom-light">
<div class="container-fluid">
<div class="row w-100">
<div class="col-md-2 col-lg-2 col-sm-4 col-xs-4">
<a class="navbar-brand" href="#">
New Project
</a>
</div>
<div class="col-md-4 col-lg-4 col-sm-6 col-xs-6 d-none d-sm-none d-md-block mt-2">
<h4 class="font-weight-600">
Little description
</h4>
</div>
<div class="col-3"></div>
<div class="col-3 mt-3 d-none d-sm-none d-md-block">
<ul class="navbar-nav pl-5">
<li class="nav-item mr-3">
<a class="nav-link" href="#">
Notification
</a>
</li>
<li class="nav-item font-weight-600 mr-3">
<a class="nav-link text-capitalize" href="#">
Hello Admin
</a>
</li>
<li class="nav-item font-weight-600 mr-3">
<a class="nav-link text-capitalize mr-3" href="#">
Profile
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
search
</a>
</li>
</ul>
</div>
</div>
</div>
</nav>
Navbar 2:
<nav class="navbar fixed-top navbar-expand-md bg-dark navbar-dark">
<!-- Brand -->
<a class="navbar-brand" href="#">Navbar</a>
<!-- 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" id="collapsibleNavbar">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
</ul>
</div>
</nav>
Here both the navbar needs to be fixed top for which i have used fixed-top class..
But as of now the navbars are overlapping each other.
You could see in the link https://www.bootply.com/y8EfMpCMc4# where the overlapping happens.
Kindly help me to place a navbar 2 below navbar 1 with position fixed (which also needs to be responsive), in which the navbar 2 alone needs to be in collapsed for small devices and needs to be on right side of navbar 1's navbrand ie.right to New Project.
Use sticky-top on the 1st instead of fixed-top, and make the 2nd navbar static by removing fixed-top.
<nav class="navbar sticky-top navbar-expand-lg navbar-light bg-custom-light"></nav>
<nav class="navbar navbar-expand-md bg-dark navbar-dark"></nav>
Demo: https://www.codeply.com/go/vbF0Sch9xc
Related:
Bootstrap 4 collapsing two navbars into one toggle button
Bootstrap 4 Multiple fixed-top navbars