I have changed the background colors of my Bootstrap menu, but the background color of the main dropdown item in the list is changing when the submenu (the menu that opens up when the dropdown item is clicked) is in focus (ie my mouse is over it).
This is the dropdown on hover (which is behaving as intended):
This is the dropdown when I have my mouse over the submenu that opens when the dropdown is clicked (the background color is not what I want; I want the background color to remain the same):
Here's the HTML:
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
Dropdown <b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li class="dropdown-header">Nav header</li>
<li>Separated link</li>
<li>One more separated link</li>
</ul>
</li>
And the CSS:
.navbar-mainnav {
background-color: #883333;
background-image: none;
}
.navbar-mainnav a, .navbar-mainnav a:hover {
color: #FFFFFF;
}
.navbar-mainnav .navbar-nav > .active > a, .navbar-nav > .active > a:hover, .navbar-nav > .active > a:focus {
color: #ffffff;
background-color:transparent;
}
.navbar-mainnav .nav > li > a:hover, .mainnav > li.dropdown.open {
background-image: none;
background-color: #B54646;
}
.navbar-mainnav .dropdown-menu > li > a:hover, .navbar-mainnav .dropdown-menu > li > a:focus {
background-color: white;
background-image: none;
filter: none;
}
.navbar-mainnav .dropdown-menu > li > a:hover {
background-color: #CC6666;
background-image: none;
}
Just put this css i think this is worked
.navbar .nav li.dropdown.open > .dropdown-toggle, .navbar .nav li.dropdown.active > .dropdown-toggle, .navbar .nav li.dropdown.open.active > .dropdown-toggle {
background-color: #B54646;
}
Maybe try this? Please post a jsfiddle so we can make sure it works.
.navbar-default .navbar-nav > li:hover {
background: #your-background-color;
color: #your-text-color;
}
Here's a working fiddle : https://jsfiddle.net/Lindow/yvyvg1ja/4/
To prevent the background from changing on dropdown click use :
.navbar-default .navbar-nav > .open > a, .navbar-default .navbar-nav > .open > a:focus, .navbar-default .navbar-nav > .open > a:hover {
background-color: #CC6666;
}
You need to style anchor tag children of the .open class, along with :hover and :focus states like so:
.navbar-mainnav .nav .open>a,
.navbar-mainnav .nav .open>a:focus,
.navbar-mainnav .nav .open>a:hover {
background: #B54646;
color: #fff;
}
Run the code snippet in full page to see how it works.
.navbar-mainnav {
background-color: #883333;
background-image: none;
}
.navbar-mainnav a, .navbar-mainnav a:hover {
color: #FFFFFF;
}
.navbar-mainnav .navbar-nav > .active > a, .navbar-nav > .active > a:hover, .navbar-nav > .active > a:focus {
color: #ffffff;
background-color:transparent;
}
.navbar-mainnav .nav > li > a:hover, .mainnav > li.dropdown.open {
background-image: none;
background-color: #B54646;
}
.navbar-mainnav .dropdown-menu > li > a:hover, .navbar-mainnav .dropdown-menu > li > a:focus {
background-color: white;
background-image: none;
filter: none;
}
.navbar-mainnav .dropdown-menu > li > a:hover {
background-color: #CC6666;
background-image: none;
}
.navbar-mainnav .nav .open>a,
.navbar-mainnav .nav .open>a:focus,
.navbar-mainnav .nav .open>a:hover {
background: #B54646;
color: #fff;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<nav class="navbar navbar-mainnav">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Brand</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active">Link <span class="sr-only">(current)</span></li>
<li>Link</li>
<li class="dropdown">
Dropdown <span class="caret"></span>
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li role="separator" class="divider"></li>
<li>Separated link</li>
<li role="separator" class="divider"></li>
<li>One more separated link</li>
</ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
Related
I'm a new to this website and for coding, i m trying to highlight active menu. i have been search almost of two weeks. still not resolved. i have tried with jquery cdn, it works, but when i upload all this to web, it doesn't work. when i click the menu it highlight and disappear suddenly. so it didnt succes with jquery cdn. here is the jquery cdn i have used.
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script type="text/javascript">
$(document).on('click', 'ul li', function(){
$(this).addClass('active').siblings().removeClass('active')
})
</script>
please help. here are my codes. if css wrong can someone of you please correct this?
<div id="main-wrap">
<nav class="navbar navbar-default ">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="/">
<div class="sidebar-pinner">
<button type="button" class="btn btn-secondary collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
</div>
<div id="scrollNav">
<ul class="nav navbar-nav navbar-left-block">
<li><span class="ico"><i class="fas fa-home"></i></span> Home</li>
<li class="currentPage"><a>Home</a></li>
</ul>
<ul class="nav navbar-nav navbar-right navbar-right-block">
<li class="user-balance"><span class="ico"><i class="material-icons">attach_money</i></span> <span class="nav-text">$0.00</span><span class="hidden badge" style="background-color: #fea621;">$0.00</span></li>
<li class="dropdown">
<span class="ico"><i class="fas fa-user-cog"></i></span> <span class="nav-text">newuserpanel</span> <span class="caret"></span>
<ul class="dropdown-menu">
<li>Account</li>
<li>API</li>
<li>Logout</li>
</ul>
</li>
</ul>
</div>
<div class="collapse navbar-collapse mobileNav" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li ><span class="ico"><img src="/home.png" alt="Home" /></span> Home</li>
<li ><span class="ico"><img src="/Services.png" alt="Services" /></span> Services</li>
<li ><span class="ico"><img src="/history.png" alt="History" /></span> history</li>
<li ><span class="ico"><img src="/Support.png" alt="Support" /></span> Support</li>
<li ><span class="ico"><img src="/FAQ.png" alt="FAQ" /></span> FAQ</li>
<li ><span class="ico"><img src="/API.png" alt="API" /></span> API</li>
<li ><span class="ico"><img src="/Terms.png" alt="Terms" /></span> Terms</li>
</ul>
</div>
</div>
</nav>
<div class="nav-bottom">
<div class="container">
<ul class="nav page-navigation">
<li ><span class="ico"><img src="home.png" alt="Home" /></span> Home</li>
<li ><span class="ico"><img src="Services.png" alt="Services" /></span> Services</li>
<li ><span class="ico"><img src="history.png" alt="Orders" /></span> History</li>
<li ><span class="ico"><img src="/API.png" alt="API" /></span> API</li>
<li class="dropdown ">
<span class="ico"><img src="/dggher5t.png" alt="chaman" /></span> Support <span class="caret"></span>
<ul class="dropdown-menu">
<li ><span class="ico"><img src="/Support.png"/></span> Support</li>
<li ><span class="ico"><img src="/FAQ.png" alt="FAQ" /></span> FAQ</li>
<li ><span class="ico"><img src="/Terms.png" alt="Terms" /></span> Terms</li>
</ul>
</li>
</ul>
</div>
</div>
here is the css
}
.dahshat-board .navbar-default {
background-color: transparent;
border-color: transparent;
padding: 10px 0;
margin: 0;
background-image: none;
}
.nav-bottom {
position: relative;
z-index: 3;
}
.nav.page-navigation {
background: #fad534;
border-radius: 500px;
display: flex;
width: 100%;
position: relative;
box-shadow: 0 2px 10px 0 rgba(0,0,0,.08);
justify-content: center;
}
.nav.page-navigation li {
display: inline-flex;
width: auto;
align-items: center;
flex: 0 0 10.85%;
flex-grow: 1;
}
.nav-bottom .nav .dropdown li {
display: block;
width: auto;
text-align: left;
}
.nav-bottom .nav li .ico {
margin-right: 4px;
width: 28px;
height: 28px;
background: #2b1f60;
border-color: #2b1f60;
}
.nav-bottom .nav li.active .ico {
background: #fad534;
border-color: #fad534;
}
.nav-bottom .nav li.active .ico img {
filter: invert(1) brightness(100%) saturate(0);
}
.nav-bottom .nav li a {
font-size: 13px;
line-height: 44px;
color: #2a1e5e;
display: flex;
justify-content: center;
position: relative;
align-items: center;
padding: 2px 9px;
border-radius: 500px;
white-space: pre;
width:100%;
}
.nav-bottom .nav li.dropdown.open a.dropdown-toggle {
/* background: transparent;
border: none; */
}
.nav-bottom .nav li a:hover,
.nav-bottom .nav li a:active,
.nav-bottom .nav li a:focus {
background: transparent;
outline: none;
}
.nav-bottom .nav .dropdown li a {
line-height: 18px;
display: block;
padding: 4px 10px;
position: relative;
}
.nav-bottom .nav .dropdown li a .badge {
position: absolute;
right: 8px;
top: 13px;
padding: 3px 7px;
font-size: 10px;
}
.nav-bottom .nav li.active a {
color: #fad534;
background-color: #270044;
}
.nav-bottom .nav .dropdown li a::after,
.nav-bottom .nav .dropdown li a::before {
display: none;
}
.navbar-collapse.mobileNav{
padding:0;
}
.navbar-collapse.collapse.mobileNav ul.navbar-nav.nav {
display: none;
}
.nav-bottom .nav li.dropdown.open .dropdown-menu a {
background: transparent;
border-radius: 0;
color: #2a1e5e;
}
.dahshat-board .navbar-default .navbar-nav > li > a {
color: #ffffff;
font-size: 14px;
padding-top: 0;
padding-bottom: 0;
display: flex;
align-items: center;
padding-top: 10px;
padding-bottom: 10px;
line-height: 34px;
}
.dahshat-board .navbar-default #scrollNav.fixedNav .navbar-nav > li > a {
color: #4d0e88;
}
.dahshat-board .navbar-default #scrollNav.fixedNav .navbar-nav > li > a .ico {
background: #480d80;
color: #efe9f5;
border: 1px solid #480d80;
}
.dahshat-board .navbar-default .navbar-nav > li > a:hover,
.dahshat-board .navbar-default .navbar-nav > li > a:focus{
color: #ffffff;
background-color:transparent;
}
.dahshat-board .navbar-default .navbar-nav > .open > a,
.dahshat-board .navbar-default .navbar-nav > .open > a:hover,
.dahshat-board .navbar-default .navbar-nav > .open > a:focus{
background: transparent;
}
.dahshat-board .navbar-default .navbar-nav.navbar-left-block .currentPage {
position: relative;
}
.dahshat-board .navbar-default .navbar-nav.navbar-left-block .currentPage::before {
content: '/';
color: #ffffff;
display: inline-block;
position: absolute;
top: 17px;
left: 0;
}
.dahshat-board .navbar-default #scrollNav.fixedNav .navbar-nav.navbar-left-block .currentPage::before{
color: #480d80;
}
.navbar-nav li.mobileSearch{
display: none;
}
The previous CSS it's a little too long, so i'll get into the explanation.
When you use this
$(document).on('click', 'ul li', ...
You're selectin any li element which is son, or grandson or so on, from any ul element. This kind of selector should be used wisely, or you may end selecting something you don't want to.
So first, try changing that into
$(document).on('click', 'ul>li', ...
To select only li elements who are direct child of ul elements.
Then, make sure that your CSS rules target to li elements with an "active" class to apply your rule and that should make it.
Edit: If this is the only thing where you're using Jquery, you may try this instead and get rid of Jquery in order to save some bandwidth when loading the page:
let prev = null;
let items = document.querySelectorAll("ul>li");
items.forEach((el)=> el.addEventListener("click", ()=>{
el.classList.add("active");
if(prev) prev.classList.remove("active");
prev = el;
});
I hope this helps enough.
So I have this code:
.hoverlist12:hover #details {
display: block;
}
The thing is the list doesn't appear at all. If I change the hoverlist12 class with the ul, it works fine, but it appears when I hover on all the elements, and I want it to appear when I hover it only on the first "li". Usually, I have no problem doing this but now I just can't figure it out.
.navbar {
border-radius: 0;
max-height: 50px;
}
.navbar-default .navbar-nav > li > a,
.navbar-default .navbar-brand {
color: #ffffff;
}
.navbar-default .navbar-brand:hover {
color: #ffffff;
transform: scale(1.1);
}
.navbar-default .navbar-nav > li > a:focus,
.navbar-default .navbar-nav > li > a:hover,
.navbar-default .navbar-brand:focus,
.navbar-default .navbar-brand:hover {
color: #ffffff;
}
.navbar-default .navbar-nav > li:focus,
.navbar-default .navbar-nav > li:hover {
background-color: rgba(0, 0, 0, 0.15);
}
nav {
font-family: "ITCErasStd-Medium";
}
.hiddeOnTop {
visibility: hidden;
}
.container-fluid {
padding-right: 3%;
padding-left: 3%;
display: inline-block;
width: 100%;
}
.navbar-default,
.container-fluid {
background-color: #be3c7a;
}
.nav > li > a {
font-size: 1.1em;
}
.navbar .facebook {
padding: 0;
margin-top: 7px;
}
.navbar .facebook:hover {
background: none;
transform: scale(1.1);
}
.navbar-brand,
.nav > li.active > a {
font-family: "ITCErasStd-Bold";
}
#details {
padding: 26px 30px;
display: none;
color: white;
z-index: 900;
font-size: 2rem;
list-style-type: none;
position: absolute;
margin-top: 50px;
background-color: #be3c7a;
}
.hoverlist12:hover #details {
display: block;
}
<nav class="mobile_nav">
<button type="button">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<ul class="nav-content">
<li>
<a href="htps://www.facebook.com" alt="facebook" class="facebook"
><img
src="./img/fb-icon.svg"
alt="fb-icon"
onerror="this.src='./img/fb-icon.png'"
/></a>
</li>
<!-- <li class="homelk">HOME</li> -->
<li class="homelk">
CE ESTE adadsadassssss
</li>
<li>INTREBARI FRECVENTE</li>
<li>PARTENERI</li>
<li>CONTACT</li>
<!-- <li><i class="fa fa-facebook-official"></i></li> -->
</ul>
</nav>
<!-- //////////////////////////// NAVBAR \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\-->
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button
type="button"
class="navbar-toggle"
data-toggle="collapse"
data-target="#myNavbar"
>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand navigate" href="#home"><span>HOssME</span></a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav navbar-right dropdown">
<li class="hoverlist12">
CE ESTE USCACIUNEA
</li>
<ul id="details">
<li>Manifestari</li>
<li>Femeia activa</li>
<li>Maternitatea</li>
<li>Menopauza</li>
<li>Sub tratament</li>
</ul>
<li> DE CE HAYLO GYN </li>
<li> INTREBARI </li>
<li>CONTACT</li>
<li>
<a href="htps://www.facebook.com" alt="facebook" class="facebook"
><img
src="./img/fb-icon.svg"
alt="fb-icon"
s
onerror="this.src='./img/fb-icon.png'"
/></a>
</li>
<!-- <li><i class="fa fa-facebook-official"></i></li> -->
</ul>
</div>
</div>
</nav>
Use selector like this: .hoverlist12:hover ~ #details Because #details and .hoverlist12 elements are siblings or at same level. You can use this selector only .hoverlist12:hover #details when #details is a child element of .hoverlist12. So, please change your CSS code as I suggested OR Please change your structure like:
<li class="hoverlist12">
CE ESTE USCACIUNEA
<ul id="details">
<li>Manifestari</li>
<li>Femeia activa</li>
<li>Maternitatea</li>
<li>Menopauza</li>
<li>Sub tratament</li>
</ul>
</li>
I want to create a sub navigation bar using bootstrap that look as in the image below. For example, the 'Advertising' tab on the main nav bar can have two sub pages named 'How It Works' and 'Our Partners'. I want the 'How It Works' and 'Our Partners' links to be shown in a subnav bar below the main nav bar when the mouse is hovered on the 'Advertising' tab. How can I do this? Tried so many examples online, but still couldn't get it working
Try this:
I used bootstrap V3.3.6
Example : https://jsfiddle.net/pfss9b28/
HTML:
<div id="navbar">
<nav class="navbar navbar-default navbar-static-top" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse" id="navbar-collapse-1">
<ul class="nav navbar-nav">
<li>About</li>
<li class="dropdown">
Advertising <b class="caret"></b>
<ul class="dropdown-menu">
<li>How It Works</li>
<li>Our Partners</li>
</ul>
</li>
<li>Press</li>
<li>Contact</li>
<li class="dropdown">
Test other child <b class="caret"></b>
<ul class="dropdown-menu">
<li>child 1</li>
<li>child 2</li>
<li>child 3</li>
<li>child 4</li>
<li>child 5</li>
</ul>
</li>
</ul>
</div>
</nav>
</div>
CSS:
.navbar-default{
background:#333;
color:#fff;
}
.navbar-default .navbar-nav > li > a{
color:#fff !important;
}
.navbar-default .navbar-nav li a:hover{text-decoration:underline}
.navbar-default .navbar-nav > li.dropdown > a{position:relative;}
.navbar-default .navbar-nav > li.dropdown:hover > a:after{
background: #333;
content: " ";
display: block;
height: 15px;
left: 20px;
position: absolute;
top: 100%;
margin-top:-10px;
transform: rotate(45deg);
width: 15px;
z-index:10001;
}
.navbar-default .navbar-nav > .active > a,.navbar-default .navbar-nav > .active > a:hover,.navbar-default .navbar-nav > li > a:hover{background:#333;color:#fff;text-decoration:underline;}
.nav > li{
position:inherit;
}
.dropdown-menu{
left: 0;
min-width: 100% !important;
position: absolute !important;
right: 0;
background:#E1E0DE;
padding:13px 0px;
}
.dropdown-menu > li{
display:inline-block;
}
.dropdown-menu > li > a:hover, .dropdown-menu > .active > a:hover {
text-decoration: underline;
background:#E1E0DE;
}
ul.nav li:hover > ul.dropdown-menu {
display: block;
}
I was attempting to change the navbar color in Bootstrap, but it was unsuccessful. The navbar just stays the same as if I never added the CSS or custom styling.
I added the custom CSS into my custom CSS file, style.css. Below is the entire contents of the style.css file.
You can also view my HTML below, which is the contents of index.htm which regard the navbar and styling.
Note: I'm using bootstrap from the latest version located at http://getbootstrap.com; not previous versions (Example: Twitter Bootstrap)
style.css
/* Custom Styling */
/* Core Styling */
body {
font-famliy: Helvetica, sans-serif;
font-size 14px;
line-height: 1.42857143;
color: #333;
}
/* Navbar Styling */
/* navbar */
.navbar-default {
background-color: #14a3ff;
border-color: #1495fe;
}
.navbar-default .navbar-brand {
color: #ecf0f1;
}
.navbar-default .navbar-brand:hover, .navbar-default .navbar-brand:focus {
color: #ecf0f1;
}
.navbar-default .navbar-text {
color: #ecf0f1;
}
.navbar-default .navbar-nav > li > a {
color: #ecf0f1;
}
.navbar-default .navbar-nav > li > a:hover, .navbar-default .navbar-nav > li > a:focus {
color: #ecf0f1;
}
.navbar-default .navbar-nav > .active > a, .navbar-default .navbar-nav > .active > a:hover, .navbar-default .navbar-nav > .active > a:focus {
color: #ecf0f1;
background-color: #1495fe;
}
.navbar-default .navbar-nav > .open > a, .navbar-default .navbar-nav > .open > a:hover, .navbar-default .navbar-nav > .open > a:focus {
color: #ecf0f1;
background-color: #1495fe;
}
.navbar-default .navbar-toggle {
border-color: #1495fe;
}
.navbar-default .navbar-toggle:hover, .navbar-default .navbar-toggle:focus {
background-color: #1495fe;
}
.navbar-default .navbar-toggle .icon-bar {
background-color: #ecf0f1;
}
.navbar-default .navbar-collapse,
.navbar-default .navbar-form {
border-color: #ecf0f1;
}
.navbar-default .navbar-link {
color: #ecf0f1;
}
.navbar-default .navbar-link:hover {
color: #ecf0f1;
}
#media (max-width: 767px) {
.navbar-default .navbar-nav .open .dropdown-menu > li > a {
color: #ecf0f1;
}
.navbar-default .navbar-nav .open .dropdown-menu > li > a:hover, .navbar-default .navbar-nav .open .dropdown-menu > li > a:focus {
color: #ecf0f1;
}
.navbar-default .navbar-nav .open .dropdown-menu > .active > a, .navbar-default .navbar-nav .open .dropdown-menu > .active > a:hover, .navbar-default .navbar-nav .open .dropdown-menu > .active > a:focus {
color: #ecf0f1;
background-color: #1495fe;
}
}
index.htm
index.htm > styling (head)
<!-- Custom Styling -->
<link rel="stylesheet" href="css/style.css" />
<!-- <link rel="stylesheet" href="css/bootstrap.min.css" /> -->
<link rel="stylesheet" href="css/bootstrap.css" />
<link rel="stylesheet" href="css/font-awesome.min.css" />
index.htm > navbar & js (out of head)
<!-- Navbar -->
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Brand</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active">Link <span class="sr-only">(current)</span></li>
<li>Link</li>
<li class="dropdown">
Dropdown <span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li>Separated link</li>
<li class="divider"></li>
<li>One more separated link</li>
</ul>
</li>
</ul>
<form class="navbar-form navbar-left" role="search">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
<ul class="nav navbar-nav navbar-right">
<li>Link</li>
<li class="dropdown">
Dropdown <span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li>Separated link</li>
</ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="js/bootstrap.js"></script>
I found the solution to the issue that was occurring. It was quite a simple issue actually.
The issue was that I was adding the bootstrap CSS in the HTML after the custom css was added.
So it should've been:
<head>
<!-- Custom Styling -->
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="css/style.css" />
</head>
Thanks for all the help.
As of Bootstrap 4 you can easily change the colour of a navbar background with the 'bg' class. A few examples are below:
<nav class="navbar navbar-expand-lg navbar-light bg-white sticky-top">
<a class="navbar-brand" href="#">
<div class="collapse navbar-collapse">
<img src="#" alt="Logo" style="width:300px;">
</a>
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="#">Home</a>
</li>
</ul>
</nav>
It is a basic navbar which expands on larger devices, collapses on smaller ones, and sticks to the top of the page. The "bg-white" element changes the background colour of the navbar from the default grey colour to white. A few more examples are:
bg-primary
bg-secondary
bg-success
bg-danger
bg-warning
bg-info
bg-light
bg-dark
bg-white
Bootstrap NavBar Generator is what you need. It is a little bit tricky when you use the CSS generated.
In case you find that after you insert the generated stylesheet the NavBar does not change at all.
Please including the following was what made it possible to change the navbar color:
.navbar{
background-image: none;
}
Hope this is helpful. :D
I'm building a site and I am utilising the Bootstrap framework as it saves me a lot of development time.
The Issue
I have a collection of links a couple of dropdown links and the rest are just regular links.
I have managed to successfully change the hover state of the links without a dropdown menu by giving them a different background colour.
But the problem I am having is that I cannot change the background colour of the links that have a dropdown menu. I don't mean the actual background colour of the dropdown menu but the nav-pill link on the navbar.
I have been trying to resolve the issue in my custom styles stylesheet (styles.css) using the following CSS code
.nav-pills {
padding-top: 20px;
}
.nav-pills > li > a {
font-size: 15px;
color: #37404e;
border-radius: 5px 5px 0 0;
padding: 10px;
}
.nav-pills > li > a:hover {
background-color: #418bca;
color: #fff;
}
/* --- dropdown-menu --- */
.dropdown-menu {
margin-top: -5px;
}
.dropdown-menu > li {
font-size: 15px;
}
.dropdown-menu > li > a {
transition: .3s;
-webkit-transition: .3s;
-moz-transition: .3s;
}
.dropdown-menu > li > a:hover {
background-color: #ff6347;
color: #fff;
}
.dropdown-header {
color: #418bca;
}
I just can't seem to find a fix for this.
Any advice on how this can be fixed would be greatly appreciated!
Try this:
DEMO:
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Brand</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav nav-pills">
<li class="active">Link</li>
<li>Link</li>
<li class="dropdown">
Dropdown <span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li>Separated link</li>
<li class="divider"></li>
<li>One more separated link</li>
</ul>
</li>
<li class="dropdown">
Dropdown <span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li>Separated link</li>
<li class="divider"></li>
<li>One more separated link</li>
</ul>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
I used these as my styles:
.navbar-default .navbar-nav .nav > li > a:hover,
.navbar-default .navbar-nav .nav > li.dropdown.active.open > a:hover,
.navbar-default .navbar-nav .nav > li.dropdown.active.open > ul.dropdown-menu > li > a:hover,
.navbar-default .navbar-nav .nav > li.dropdown.open > a:hover,
.navbar-default .navbar-nav .nav > li.dropdown.open > ul.dropdown-menu a:hover,
.navbar-default .navbar-nav .nav > li.dropdown.open > a,
.navbar-default .navbar-nav .nav > li.dropdown.open > ul.dropdown-menu a,
{
background-color: #fff;
border-color: #fff;
}
You may need to change the selectors before the first > depending on your structure of your HTML.