I have a navbar on my page but for some reason only the 'homepage' link is pure white. the rest of the links are not as bright. I am trying to create a transparent navbar with a picture as a background. i have managed to do that but the 'Home' link is considerably brighter and more prominent then the rest of the links. the image can be seen below:
<div class="container-fluid p-0">
<nav class="navbar navbar-expand-lg fixed-top navbar-dark">
<a class="navbar-brand" href="#">
<i class="fas fa-mountain fa-2x mx-3"></i>Greatness</a> <!--This is the icon for the brand-->
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav"
aria-controls="navbarNav" aria-expanded="false"
aria-label="Toggle navigation">
<i class="fas fa-align-right text-light"></i>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<div class="mr-auto"></div>
<ul class="navbar-nav justify-content-center">
<li class="nav-item active">
<a class="nav-link" href="indexHome.html">HOME</a>
</li>
<li class="nav-item">
<a class="nav-link" href="AboutUs.html">ABOUT US
<span class="sr-only">(current)</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">IDEAS</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">MOTIVATION</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">LOG IN</a>
</li>
</ul>
</div>
</nav>
</div>
CSS
.nav-item:last-child{
padding-right: 10.5em;
}
.nav-item{
padding: 0.9em;
color: white;
font-size: 17px;
}
.navbar-brand{
padding-left: 8em;
}
It is because an active class is defined in the li which is wrapped around it, like <li class="nav-item active">. Add the active class to its siblings and it should work.
Related
I used a bootstrap navbar, I created a hover effect and the problem is that when I click on a tab, the color changes in white but there is still a black margin.
Here is how it looks like:
how it is
And here is how I want it to look like:
how it should be
Here is the code:
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container">
<a class="navbar-brand" href="#">Elegant<i class="fa fa-square"></i></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 ms-auto">
<li class="nav-item">
<a class="nav-link" href="#homepage">HOMEPAGE</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">PAGE</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">FEATURE</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">PRICING</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">BLOG</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#"><i class="fa-solid fa-magnifying-glass"></i></a>
</li>
</ul>
</div>
</div>
</nav>
CSS
.nav-item a {
font-size: 12px;
color: white;
letter-spacing: 2.5px;
padding: 25px !important;
display: block;}
.nav-item a:hover {
background-color: white;
color: black;}
Make the padding of the relevant container to be 0, that is the navbar.
.nav-item a {
font-size: 12px;
color: white;
letter-spacing: 2.5px;
padding: 25px !important;
display: block;
}
.nav-item a:hover {
background-color: white;
color: black;
}
.navbar {
--bs-navbar-padding-y: 0;
padding-top: 0 !important;
padding-bottom: 0 !important;
}
<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-expand-lg navbar-dark bg-dark">
<div class="container">
<a class="navbar-brand" href="#">Elegant<i class="fa fa-square"></i></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 ms-auto">
<li class="nav-item">
<a class="nav-link" href="#homepage">HOMEPAGE</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">PAGE</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">FEATURE</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">PRICING</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">BLOG</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#"><i class="fa-solid fa-magnifying-glass"></i></a>
</li>
</ul>
</div>
</div>
</nav>
In mobile view as i click on hamburger button the dropdown menu gets overlapped with the content.Even while scrolling down the content is being overlapped.
<div class="background my-0 mx-0 fixed-top">
<nav id="mainNavbar" class="navbar navbar-expand-lg navbar-light ">
<a class="navbar-brand" href="#">TAVISH DESIGN STUDIO</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 justify-content-end">
<li class="nav-item">
<a class="nav-link active" href="#">HOMEPAGE</a>
</li>`enter code here`
<li class="nav-item">
<a class="nav-link" href="#">OUR CLIENTS</a>
</li>`enter code here`
<li class="nav-item">
<a class="nav-link" href="#">ABOUT US</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">CAREERS</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">CONTACT US</a>
</li>
</ul>
</div>
</nav>
</div>
Add background solid color to navbar list like below:
.navbar-collapse.show {
background: white;
}
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>
I'm trying to created a fixed-top navbar using Bootstrap 4 however I'm having a very difficult time trying to align the LOGO and MENU items to my liking.
I understand there is ml-auto, mr-auto however, is it possible for me to add pixels to it so I move it exactly how I want to?
This is what my navbar looks like:
I am hoping to move the LOGO and the MENU items towards the middle of the screen. maybe start with padding of 100px from right and left, so LOGO and MENU are closer together. Here is my code:
<nav class="navbar navbar-expand-lg navbar-dark sticky-dark bg-dark">
<a class="navbar-brand" href="#">LOGO</a>
<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 id="navbarNavDropdown" class="navbar-collapse 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="#">ABOUT</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">SERVICES</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">CONTACT</a>
</li>
</ul>
</div>
</nav>
You can add padding to the main .navbar element. Then control the spacing using media queries.
.navbar {
padding: 0.5em 100px !important;
}
#media only screen and (max-width: 768px) {
.navbar {
padding: 0.5em 1em !important;
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/css/bootstrap.min.css" />
<nav class="navbar navbar-expand-lg navbar-dark sticky-dark bg-dark">
<a class="navbar-brand" href="#">LOGO</a>
<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 id="navbarNavDropdown" class="navbar-collapse 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="#">ABOUT</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">SERVICES</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">CONTACT</a>
</li>
</ul>
</div>
</nav>
I want to remove the padding-left of the first .nav-link in .navbar-nav.
Here's an example.
In bootstrap 4 I created a nav and gave padding to .nav-link:
.navbar-dark .navbar-nav .nav-link {
color: #fff;
padding-left: 1rem;
padding-right: 1rem;
}
<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/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<section class="navigation container-fluid">
<nav class="container navbar navbar-expand-lg navbar-dark">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#mainNavbar" aria-controls="mainNavbar" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="mainNavbar">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="http://www.flakneconstructionllc.com">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="about">About Us</a>
</li>
<li class="nav-item">
<a class="nav-link" href="services">Services</a>
</li>
<li class="nav-item">
<a class="nav-link" href="gallery">Gallery</a>
</li>
<li class="nav-item">
<a class="nav-link" href="contact">Contact Us</a>
</li>
</ul>
</div>
</nav>
</section>
But it's not working because there is a .nav-item between the .navbar-nav & .nav-link.
Do you guys have any solution?
How can I select first item in this case?
The easiest way is with the pl-0 padding utility class. You can use it on the first nav-link, and on the navbar too if you want to remove all of the left whitespace.
<section class="navigation container-fluid">
<nav class="container pl-0 navbar navbar-expand bg-dark navbar-dark">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#mainNavbar" aria-controls="mainNavbar" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="mainNavbar">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link pl-0" href="http://www.flakneconstructionllc.com">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="about">About Us</a>
</li>
<li class="nav-item">
<a class="nav-link" href="services">Services</a>
</li>
<li class="nav-item">
<a class="nav-link" href="gallery">Gallery</a>
</li>
<li class="nav-item">
<a class="nav-link" href="contact">Contact Us</a>
</li>
</ul>
</div>
</nav>
</section>
https://www.codeply.com/go/hIgX0LyIaB
To use CSS to target the first link use...
.navbar-nav .nav-item:first-child .nav-link {
padding-left: 0;
}