Having a hard time positioning image behind Bootstrap navbar (Z-index) - html

This is the navbar layout
<header id="navigation-bar" class="nav-header">
<nav class="navbar navbar-expand-lg">
<a class="navbar-brand" href="#">
<img src="images/logo.svg" alt="logo-icon">
</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">
<li class="nav-item active">
<a class="nav-link" href="#">How we work <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item item2 active">
<a class="nav-link" href="#">Blog<span class="sr-only">(current)</span></a>
</li>
<li class="nav-item item2 active">
<a class="nav-link" href="#">Account <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item active">
<a class="nav-link nav-btn-link" href="#"><button class="nav-btn btn btn-outline-dark">View Plans</button><span class="sr-only">(current)</span></a>
</li>
</ul>
</div>
</nav>
</header>
bg-img1 is the image I'm trying to position behind navbar:
<section id="Heading">
<img class="bg-img1" src="images/bg-pattern-intro-right-desktop.svg" alt="bg-pattern-left">
<div class="container-1">
<div class="heading-text">
I tried putting a header around the navbar and positioning the z-index but it doesnt seem to do it justice.
.nav-header {
position: relative;
padding: 1%;
z-index: 10000;
}
and this is how I positioned my image:
.bg-img1 {
position: absolute;
right: 0;
width: 40%;
top: 3%;
z-index: 2;
}

You are doing everything right but because you are giving src to your img attribute, as a result of which it will be treated as an image which will not be appearing behind the navbar but in front.
Instead of giving src to your image, you can use CSS background property for your img attribute which will make the img appear behind the navbar. So no need of any z-index
.bg-img1 {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: url(https://images.unsplash.com/photo-1590845947667-381579052389?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60) no-repeat;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/css/all.min.css" rel="stylesheet" />
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<section id="Heading">
<img class="bg-img1" alt="bg-pattern-left">
<div class="container-1">
<div class="heading-text">
</div>
</div>
</section>
<header id="navigation-bar " class="nav-header">
<nav class="navbar bg-dark navbar-expand-lg">
<a class="navbar-brand" href="#">
<img src="https://placehold.it/20x20" alt="logo-icon">
</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">
<li class="nav-item active">
<a class="nav-link" href="#">How we work <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item item2 active">
<a class="nav-link" href="#">Blog<span class="sr-only">(current)</span></a>
</li>
<li class="nav-item item2 active">
<a class="nav-link" href="#">Account <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item active">
<a class="nav-link nav-btn-link" href="#"><button class="nav-btn btn btn-outline-dark">View
Plans</button><span class="sr-only">(current)</span></a>
</li>
</ul>
</div>
</nav>
</header>

Related

Creating a slideable navigation bar using Bootstrap for web and mobile devices

I am using Bootstrap 4.5.0 (both have the css and script from the CDN on my webpage). I am trying to make a responsive navigation bar header like the Bootstrap website does, which works well for desktop web browsers and mobile devices as well. My goal I am having trouble with is making the navbar list items be slideable/scrollable from left to right and back again when on a mobile device or a small screen.
The Bootstrap header on a small screen works well like:
So the above snapshot of Bootstraps site on a small window show Home, Documentation, ... to Themes and is slideable left to right and back with the mouse (desktop) or finger (mobile device).
See the snapshot below after pulling Themes to the left:
I am having trouble accomplishing this with my code and Bootstrap which is shown below:
<header class="navbar navbar-expand navbar-light flex-column flex-md-row bd-navbar" style="background-color: yellow;">
<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="navbar-nav-scroll">
<ul class="navbar-nav bd-navbar-nav flex-row">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item active">
<a class="nav-link" href="#">Start Test</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="#">Testaaa</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="#">Testbbb</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="#">Testccc</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="#">Testddd</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="#">Testeee</a>
</li>
</ul>
</div>
</header>
Currently my code does not slide at all and I need some help figuring out what I am missing. Thanks.
I have included 2 CSS paths with your code and the sliding effect is working fine. Do you have these 2 paths included?
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<link rel="stylesheet" href="https://getbootstrap.com/docs/4.5/assets/css/docs.min.css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<link rel="stylesheet" href="https://getbootstrap.com/docs/4.5/assets/css/docs.min.css">
<header class="navbar navbar-expand navbar-light flex-column flex-md-row bd-navbar" style="background-color: yellow;">
<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="navbar-nav-scroll">
<ul class="navbar-nav bd-navbar-nav flex-row">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item active">
<a class="nav-link" href="#">Start Test</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="#">Testaaa</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="#">Testbbb</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="#">Testccc</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="#">Testddd</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="#">Testeee</a>
</li>
</ul>
</div>
</header>
Here's is the solution.Please run it on mobile view of browser.I have used both overflow:hidden and overflow-x:auto to make this working.
.bd-navbar {
box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, .05), inset 0 -1px 0 rgba(0, 0, 0, .1);
}
.bd-navbar .navbar-nav .nav-link.active, .bd-navbar .navbar-nav .nav-link:hover {
color: white!important;
background-color: transparent;
}
#media all and (max-width: 991px) {
.bd-navbar {
padding-right: 0.5rem;
padding-left: 0.5rem;
}
.bd-navbar .navbar-nav-scroll {
max-width: 100%;
height: 2.5rem;
margin-top: 0.25rem;
overflow: hidden;
}
.bd-navbar .navbar-nav-scroll .navbar-nav {
padding-bottom: 2rem;
overflow-x: auto;
white-space: nowrap;
-webkit-overflow-scrolling: touch;
}
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<header class="navbar navbar-expand navbar-light flex-column flex-md-row bd-navbar" style="background-color: yellow;">
<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="navbar-nav-scroll">
<ul class="navbar-nav bd-navbar-nav flex-row">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item active">
<a class="nav-link" href="#">Start Test</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="#">Testaaa</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="#">Testbbb</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="#">Testccc</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="#">Testddd</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="#">Testeee</a>
</li>
</ul>
</div>
</header>

How can I place my elements inside my navbar?

The elements of my navbar seem to be stuck outside of it. I'm not sure why?
Here's my code:
<nav class="navbar navbar-expand-lg navbar-inverse"></nav>
<div class="container-fluid">
<div class="navbar-header">
<a
style="color: black; text-decoration: none; font-size: 2rem;"
class="navbar-brand"
href="#"
>name<span class="fas fa-microscope fa-1x"></span
></a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<i class="material-icons">menu</i>
</button>
</div>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Dashboard <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">Protect</li>
<li class="nav-item">About</li>
</ul>
</div>
</nav>
.nav a{
color: white !important;
font-size: 20px;
}
.navbar-brand{
color: white !important;
font-size: 20px;
font-family: sans-serif;
}
And here's what the navbar looks like:
website
Does anyone know how to fix this? (Also does the menu icon have a white background and is black, whereas the microscope icon has an invisible bg and is white?)
Thanks!
You close the navbar in the beginning, so remove the </nav> tag from your first line.
Remove 2nd line, it is unnecessary code here.
Assign class "nav-link" for "Protect" & "About menu".
<nav class="navbar navbar-expand-lg navbar-inverse">
<div class="navbar-header">
<a
style="color: black; text-decoration: none; font-size: 2rem;"
class="navbar-brand"
href="#">name<span class="fas fa-microscope fa-1x"></span></a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<i class="material-icons">menu</i>
</button>
</div>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Dashboard <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item"><a class="nav-link" href="#">Protect</a></li>
<li class="nav-item"><a class="nav-link" href="#">About</a></li>
</ul>
</div>
</nav>

How to center a logo on my bootstrap navbar [duplicate]

This question already has answers here:
Bootstrap NavBar with left, center or right aligned items
(14 answers)
Centering brand logo in Bootstrap Navbar
(7 answers)
Closed 2 years ago.
I'm trying to place a logo on my navbar, right in the center. The navbar automatically stretches to be the same size as the image which I don't want. How do I put a logo on my navbar that overlaps/doesn't stretch the navbar?
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<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 mx-auto ">
<li class="nav-item active ">
<a class="nav-link " href="#">Home <span class="sr-only">(current)</span></a>
</li>
<div class="navbar-brand">
<img src = "test-logo.png" height="250" width="250" alt="test logo">
</div>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
</ul>
</div>
</nav>
Hello here is the example code for your problem..
.navbar-brand {margin: 0 30px;padding: 0;}
.navbar-brand img {max-height: 68px;}
nav.navbar .navbar-nav li a {
padding: 0 20px;
line-height: 68px;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet"/>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<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="navbar-brand d-block d-md-none">
<img src="https://www.jing.fm/clipimg/full/135-1359070_test-logos-full-logo-with-text-and-simple.png" width="60px" alt="logo" />
</div>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mx-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="#">About</a>
</li>
<li class="nav-item">
<a class="nav-link " href="#">Services</a>
</li>
<div class="navbar-brand d-none d-md-block">
<img src="https://www.jing.fm/clipimg/full/135-1359070_test-logos-full-logo-with-text-and-simple.png" alt="logo" />
</div>
<li class="nav-item">
<a class="nav-link" href="#">Blog</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">career</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact</a>
</li>
</ul>
</div>
</nav>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js#1.16.0/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>

Bootstrap main header with image background

I have a simple main header which contain a navbar , I want an image background to the main header.
Here is jsfidle:http://jsfiddle.net/Mwanitete/fgkq759n/8/
Here is html:
<div class="marketing-main-header_banner">
<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="#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 ml-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Dla kogo <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Agenda</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Prowadzacy</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Faq</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Kontakt</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Kompetencje</a>
</li>
</ul>
</div>
</nav>
</div>
here is css
html, body{
height: 100%;
margin: 0px;
}
* {
box-sizing: border-box;
}
.marketing-main-header_banner{
background-image: url("https://thumb.ibb.co/eodzqU/Path_47.png" alt="Path_47");
background-size: cover;
background-repeat: no-repeat;
background-position: 100% 100%;
position: relative;
height: 900px;
}
Here is what I have :
my solution displays navbar on top and the image is below the navbar?
Here is what I want:
what am I missing in my code???
Try
.navbar-custom {
background-color: rgba(0,0,0,0);
}
And add the navbar-custom class to your opening tag, like this
<nav class="navbar navbar-expand-lg navbar-light bg-light navbar-custom">
Hopefully this will work.
You can try with this code i hope it's will work!
<div class="marketing-main-header_banner">
<nav class="navbar fixed-top navbar-light bg-light">
<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 ml-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Dla kogo <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Agenda</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Prowadzacy</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Faq</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Kontakt</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Kompetencje</a>
</li>
</ul>
</div>
</nav>
</div>

adding components before hamburger bootstrap4

I've got a navbar in Bootstrap 4:
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<header class="row">
<div class="w-100">
<nav class="navbar navbar-toggleable-md navbar-light bg-faded">
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="p-2" id="menuLabel">MENU</span><span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand" href="#">
<img src="../img/svg/stopa-logo.svg" width="120">
</a>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav menu-margined-right">
<li class="nav-item">
<a class="nav-link" href="#">Missions</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">About Us</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">We Support</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact Us</a>
</li>
</ul>
</div>
<ul class="nav navbar-nav lang-right">
<li class="nav-link">
<a class="nav-item" href="#">CZ</a>
</li>
<li class="nav-link">
<a class="nav-item" href="#">EN</a>
</li>
</ul>
</nav>
</div>
</header>
and I want to make that the language switch links will be before "MENU" burger, is this possible?:
LINK
Any ideas how I can do that? I haven't been able to find a solution.
Make ul absolute and place it with top and right coordinates.
Set both ul and li's to inline-block.
Example below:
ul.nav.navbar-nav.lang-right {
position: absolute;
right: 160px;
top: 7px;
display: inline-block;
}
li.nav-link {
display: inline-block;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.3.7/js/tether.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js"></script>
<header class="row">
<div class="w-100">
<nav class="navbar navbar-toggleable-md navbar-light bg-faded">
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="p-2" id="menuLabel">MENU</span><span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand" href="#">
<img src="../img/svg/stopa-logo.svg" width="120">
</a>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav menu-margined-right">
<li class="nav-item">
<a class="nav-link" href="#">Missions</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">About Us</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">We Support</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact Us</a>
</li>
</ul>
</div>
<ul class="nav navbar-nav lang-right">
<li class="nav-link">
<a class="nav-item" href="#">CZ</a>
</li>
<li class="nav-link">
<a class="nav-item" href="#">EN</a>
</li>
</ul>
</nav>
</div>
</header>