Show background image in a div underneath navbar - html

New to bootstrap.
I want to show a background image underneath the NavBar within a div in bootstrap. For some reason the image in the code below is not rendering correct height. How do i achieve the correct height whilst at the same time maintaining the responsiveness of the image?
Also, how can we change the color of the NavBar on scroll? Nothing happens with the code below when I scroll.
Html:
<nav class="navbar navbar-expand-lg bg-secondary fixed-top text-uppercase" id="mainNav">
<div class="container">
<a class="navbar-brand js-scroll-trigger" href="#page-top"> <img src="img/logo-clear.png" alt="logo" style="width:160px;"></a>
<button class="navbar-toggler navbar-toggler-right text-uppercase bg-primary text-white rounded" type="button" data-toggle="collapse" data-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 ml-auto">
<li class="nav-item mx-0 mx-lg-1">
<a class="nav-link py-2 px-0 px-lg-3 rounded js-scroll-trigger" href="#portfolio">Portfolio</a>
</li>
<li class="nav-item mx-0 mx-lg-1">
<a class="nav-link py-2 px-0 px-lg-3 rounded js-scroll-trigger" href="#about">About</a>
</li>
<li class="nav-item mx-0 mx-lg-1">
<a class="nav-link py-2 px-0 px-lg-3 rounded js-scroll-trigger" href="#services">Services</a>
</li>
<li class="nav-item mx-0 mx-lg-1">
<a class="nav-link py-2 px-0 px-lg-3 rounded js-scroll-trigger" href="#contact">Contact</a>
</li>
</ul>
</div>
</div>
</nav>
<!-- Header -->
<div class="page-header bg-primary" style="background-image: url(./img/1.jpg);">
<p class="text-center text-uppercase text-secondary mb-0" id="mainText">Portfolio</p>
</div>
</div>
CSS:
/*for navbar*/
.bg-secondary {
background-color: transparent !important;
/* background-color: transparent !important; */
}
.bg-secondary.scrolled{
background-color: #333300 !important;
}
.page-header{
background-size: cover;
height: auto;
}
JS:
<script>
$(window).scroll(function(){
$('nav').toggleClass('scrolled', $(this).scrollTop() > $('nav'));
});
</script>

Something like this? https://jsfiddle.net/wwWaldi/nrysp61w/10/
You gotta set the height to your header, (i changed the url of the header for demo)
height: 300px;

Related

navbar item allign bottom with logo

I create one the Nav and put the logo on the top left, as the logo size is bigger, all of nav item now place on top left, can I know how to move them into bottom / centre?
Here is nav bar code
<div class="full-width">
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3 align-items-start">
<img src="~/resources/images/projectLogo.jpg" alt="St Mary School" style="margin: 10px 10px 10px 10px">
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index" style="align-self:flex-end">Lesson School Project</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse d-sm-inline-flex flex-sm-row-reverse">
<ul class="navbar-nav flex-grow-1" >
<li class="nav-item" >
<a class="nav-link text-dark" asp-area="" asp-controller="Main" asp-action="Index" >Lesson Search</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Main" asp-action="PureChart">Result Chart</a>
</li>
</ul>
</div>
</nav>
</div>
Thank you for help
replace align-items-start to align-items-center in nav tag.

Unabe to expand data-toggle dropdown to full width of screen

I'm trying to extend my navbar data-toggle dropdown to the full width of the screen. For some reason, it still leaves white space on the left side when I set the viewport width to 100. I'm using bootstrap and setting a media query in my CSS which I'll show below.
<nav class="navbar navbar-expand-sm navbar-dark fixed-top bg-primary">
<div class="container">
<a class="navbar-brand text-white">Vince Clicks</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarToggler"
aria-controls="navbarToggler" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse bg-primary" id="navbarToggler">
<ul class="navbar-nav text-center mx-auto mb-2 mb-sm-0">
<li class="nav-item">
<a class="nav-link active" href="#home">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#about">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#skills">Skills</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#contact">Contact</a>
</li>
</ul>
<div class="d-none d-sm-flex">
<a class="btn btn-social-icon btn-linkedin" href="#"><i
class="fab fa-2x fa-github-square"></i></a>
<a class="btn btn-social-icon btn-linkedin" href="http://www.linkedin.com/in/"><i
class="fab fa-2x fa-linkedin"></i></a>
</div>
</div>
</div>
</nav>
#media (max-width: 576px){
.navbar-nav{
margin-top: 11px;
max-height: 158px;
width: 100vw
}
.nav-link{
border-top: 1px solid black;
}
}
The .container has left and right padding (x-axis), remove it by adding .px-0 and your example works. There is no need to set the width in your media query.
In the following snippet, in order to compensate for the lost padding
I have added margins to .navbar-brand and .navbar-toggler
with .ms-3 and .me-3, respectively:
#media (max-width: 576px) {
.navbar-nav {
margin-top: 11px;
max-height: 158px;
}
.nav-link {
border-top: 1px solid black;
}
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous">
<nav class="navbar navbar-expand-sm navbar-dark fixed-top bg-primary">
<div class="container px-0">
<a class="navbar-brand text-white ms-3">Vince Clicks</a>
<button class="navbar-toggler me-3" type="button" data-bs-toggle="collapse" data-bs-target="#navbarToggler" aria-controls="navbarToggler" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse bg-primary" id="navbarToggler">
<ul class="navbar-nav text-center mx-auto mb-2 mb-sm-0">
<li class="nav-item">
<a class="nav-link active" href="#home">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#about">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#skills">Skills</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#contact">Contact</a>
</li>
</ul>
<div class="d-none d-sm-flex">
<a class="btn btn-social-icon btn-linkedin" href="#"><i class="fab fa-2x fa-github-square"></i></a>
<a class="btn btn-social-icon btn-linkedin" href="http://www.linkedin.com/in/"><i class="fab fa-2x fa-linkedin"></i></a>
</div>
</div>
</div>
</nav>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-/bQdsTh/da6pkI1MST/rWKFNjaCP5gBSY4sEBT38Q/9RBh9AH40zEOg7Hlq2THRZ" crossorigin="anonymous"></script>

Navbar is overlapping my content. bootstrap 4

I started to edit my web and I added second logo in navbar. It looks okay on pc but when I try it on mobile, navbar is covering image.. I am using bootstrap 4 so I would like to know how that navbar is up the image and not in image... Thanks.
<nav id="menu" class="navbar fixed-top navbar-toggleable-sm bg-faded px-5 stin">
<button class="navbar-toggler navbar-toggler-right mr-3" 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="row d-flex align-items-end">
<div class="col-1 col-md-2 mr-1 mr-sm-0">
<a class="navbar-brand" href="#"> <img src="img/logo_barva.svg" height="90" class="pb-1"></a>´
</div>
</div>
<div class="collapse navbar-collapse prava pr-3" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto ">
<li class="nav-item active">
<a class="nav-link" href="#">DOMŮ<span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="uklid.html">ÚKLIDOVÉ SLUŽBY</a>
</li>
<li class="nav-item">
<a class="nav-link" href="pece.html">DOMA PÉČE</a>
</li>
<!--<li class="nav-item dropdown">
SLUŽBY<span class="caret"></span>
<ul class="dropdown-menu col-xs-12" >
<li><a class="dropdown-item" href="uklid.html">Úklidové služby</a></li>
<li><a class="dropdown-item" href="pece.html">Domácí péče</a></li>
</ul>
</li>-->
<li class="nav-item">
<a class="nav-link" href="kariera.html">KARIÉRA</a>
</li>
<li class="nav-item">
<a class="nav-link" href="kontakt.html">KONTAKT</a>
</li>
</ul>
</div>
<div class="logo2">
<div class="col-5 col-md-2 mr-1 mr-sm-0">
<a class="navbar-brand pr-5" href="pece.html"> <img src="img/doma_pece.png" height="65" class="pb-1"></a>´
</div>
</div>
Well, I managed to do it.
If someone needed it:
#media screen and (max-width: 768px) {
body {
padding-top: 15.3rem;
padding-bottom: 0rem;
color: #5a5a5a;
}
}

Bootstrap navbar logo overlay

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;
}
}

Bootstrap Navbar Brand left, collapsible icons in center, and single item right

I've been trying to do this for to days now without any complete result, I've been trying codes from another questions made here and nothing. I want my navbar-brand to be in the left, some icons in the center and one icon in the right, I want all of them to be collapsable. I tried everything but the flexbox didn't work for me on the collapsable div, the only thing I could do and is the most approachable to my goal is this:
<nav class="navbar navbar-expand-lg bg-bee navbar-bee justify-content-between" role="navegador">
<a class="navbar-brand" href="#">Brand</a>
<button class="navbar-toggler ml-auto" type="button" data-target="#navegador" data-toggle="collapse" aria-label="Expandir navegador" aria-expanded="false">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-nav">
<a data-toggle="tooltip" data-placement="bottom" title="Comprar" class="d-none d-lg-block nav-item nav-link rounded" href="#"><span class="far fa-handshake icon-nav"></span></a>
<a data-toggle="tooltip" title="Vender" class="d-none d-lg-block nav-item nav-link rounded" href="#"><span class="fas fa-hand-holding-usd icon-nav"></span></a>
<a data-toggle="tooltip" title="Mi carrito" class="d-none d-lg-block nav-item nav-link rounded" href="#"><span class="fas fa-shopping-cart icon-nav"></span></a>
</div>
<div class="navbar-nav">
<form id="form-iSesion" action="procesos.php" method="POST">
<a data-toggle="tooltip" title="Entrar o registrarse" id="iSesion" class="d-none d-lg-block nav-item nav-link rounded" href="#"><span class="fas fa-user icon-nav"></span></a>
<input type="hidden" name="menu" value="1">
</form>
</div>
<!--<div class="collapse navbar-collapse bg-primary" id="navegador">
<div class="navbar-nav">
<a data-toggle="tooltip" data-placement="bottom" title="Comprar" class="d-md-block d-lg-none nav-item nav-link rounded" href="#"><span class="far fa-handshake icon-nav"></span></a>
<a data-toggle="tooltip" title="Vender" class="nav-item nav-link rounded" href="#"><span class="d-md-block d-lg-none fas fa-hand-holding-usd icon-nav"></span></a>
<a data-toggle="tooltip" title="Mi carrito" class="d-md-block d-lg-none nav-item nav-link rounded" href="#"><span class="fas fa-shopping-cart icon-nav"></span></a>
<form id="form-iSesion" action="procesos.php" method="POST">
<a data-toggle="tooltip" title="Entrar o registrarse" id="iSesion" class="d-md-block d-lg-none nav-item nav-link rounded" href="#"><span class="fas fa-user icon-nav"></span></a>
<input type="hidden" name="menu" value="1">
</form>
</div>
</div>-->
</nav>
With this result:
Full display
Responsive behavior
But once I active the collapsable navbar, everything get disordered again because that container is occupying a lot of space and anything that I've tried fix it
Disordered
If I add a background you can see how much space it's occupying
collapsable with background
Sincerely I don't know what else try, this is making me crazy.
EDIT: ZimSystem solution works, but there's a problem. When the items collapse, every one of them is occupying an entire row. I want a display-inline for them when the menu collapses, an option would be to display all of them horizontally
There are a few different ways using Bootstrap 4, but the simplest I think is to separate the navbar-collapse, give each Navbar section a defined width (using w-*), and then using the toggler to toggle both navbar-collapse.
<nav class="navbar navbar-expand-lg bg-light navbar-light" role="navegador">
<a class="navbar-brand w-25" href="#">Brand</a>
<button class="navbar-toggler" type="button" data-target=".navbar-collapse" data-toggle="collapse" aria-label="Expandir navegador" aria-expanded="false">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse w-50" id="navegador">
<div class="navbar-nav mx-auto justify-content-center">
<a data-toggle="tooltip" data-placement="bottom" title="Comprar" class="nav-item nav-link rounded" href="#"><span class="far fa-handshake icon-nav"></span></a>
<a data-toggle="tooltip" title="Vender" class="nav-item nav-link rounded" href="#"><span class="fas fa-hand-holding-usd icon-nav"></span></a>
<a data-toggle="tooltip" title="Mi carrito" class="nav-item nav-link rounded" href="#"><span class="fas fa-shopping-cart icon-nav"></span></a>
</div>
</div>
<div class="collapse navbar-collapse w-25" id="navegador2">
<form id="form-iSesion" class="navbar-nav w-100 justify-content-end" action="procesos.php" method="POST">
<a data-toggle="tooltip" title="Entrar o registrarse" id="iSesion" class="nav-item nav-link rounded" href="#"><span class="fas fa-user icon-nav"></span></a>
<input type="hidden" name="menu" value="1">
</form>
</div>
</nav>
https://www.codeply.com/go/FlImrjvZ0o
Here's a generic example, using Bootstrap v4, doing what you asked for. By default, the "center" menu is centered in the available space between logo and right menu. Note the ml-auto mr-auto classes on the middle element. They apply auto to left and right margins, centering it.
If you want a perfect center inside the browser, your only option is to make the brand and the right menu have equal width in the flow of their parent. One quick way is to take them out of their parent flow using position:absolute, but you'll need to position the logo and the right menu using top/left/right properties, and make sure they don't overlap with the center menu on any responsiveness interval.
But the simplest fix is to add a margin to the smaller one, so it gets to the size of the bigger one. In the example below I added a right margin of 22px to the logo, which is the difference between its width and the right menus' width. (86.25 - 64.48):
#media (min-width: 992px) {
nav .navbar-brand {
margin-right: 22px;
}
}
/* YOU DON'T NEED THE CSS BELOW, I ADDED IT TO
SHOW THE MENU IS CENTERED */
/* marking the center of the nav */
#media (min-width: 992px) {
nav:after {
width: 3px;
content: '';
position: absolute;
background-color: red;
height: 100px;
left: 50%;
transform: translateX(-50%);
top: 100%;
}
}
/* marking the center of the navbar-nav */
#media (min-width: 992px) {
.navbar-nav.ml-auto.mr-auto {
position: relative;
}
.navbar-nav.ml-auto.mr-auto:after {
width: 1px;
content: '';
position: absolute;
background-color: black;
height: 50px;
left: 50%;
transform: translateX(-50%);
top: 100%;
z-index: 1;
}
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" 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.0/umd/popper.min.js" integrity="sha384-cs/chFZiN24E4KMATLdqdvsezGxaGsi4hLGOzlXwp5UZB1LY//20VyM2taTB4QvJ" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js" integrity="sha384-uefMccjFJAIv6A+rW+L4AHf99KvxDjWSu1z9VI8SKNVmz4sk7buKt/6v9KI65qnm" crossorigin="anonymous"></script>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" 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" id="navbarSupportedContent">
<ul class="navbar-nav ml-auto mr-auto">
<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>
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="#">Some link</a>
</li>
</ul>
</div>
</nav>
Alernatively, this can be done via Javascript:
(function($) {
let centerMenu = function() {
let $left = $('.navbar-brand'),
$right = $('.navbar-nav', 'nav').last(),
hasWidth = function(e) {
return e.is('*') && e.width() > 0
}
if (hasWidth($left) && hasWidth($right) && $(window).width() > 992) {
if ($left.width() > $right.width()) {
$right.css({
marginLeft: ($left.width() - $right.width()) + 'px'
});
} else {
$left.css({
marginRight: ($right.width() - $left.width()) + 'px'
})
}
$(window).off('load resize', centerMenu);
}
};
$(window).on('load resize', centerMenu);
})(jQuery)
jsFiddle.