bootstrap 3 navbar dropdown-toggle not applies all css style - css

I'm modifing bootstrap 3 navbar and some CSS properties doesn't apply...
I have this navbar HTML:
<nav class="navbar navbar-default">
<div id="navbar-principal" class="container-fluid">
<div id="navbar-colapsado" class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a id="logo" class="navbar-brand" (click)="onClick('Inicio')" [class.active]="'Inicio'===itemSelected" [routerLink]="['/']"><img src="app/img/logo.jpg" alt="Logo"></a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li><a [routerLink]="['/link']">Inicio</a></li>
<li role="button" class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Info<span class="caret">
</span></a>
<ul class="dropdown-menu">
<li><a [routerLink]="['/linkA']">Mis Compras</a></li>
<li><a [routerLink]="['/linkB']">Mis Facturas</a></li>
<li><a [routerLink]="['/linkC']">Mi Cuenta</a></li>
</ul>
</li>
<li>Other links</li>
<li>Other links</li>
<li>Other links</li>
</ul>
</div><!--/.nav-collapse -->
</div><!--/.container-fluid -->
</nav>
I load bootstrap 3 form CDN and override with this CSS code:
:host .nav.navbar-nav.navbar-right > li.dropdown.open,
.nav.navbar-nav.navbar-right > li.dropdown.open > a,
.nav.navbar-nav.navbar-right > li.dropdown.open > a:hover{
color: yellow;
background-color: rgba(61, 164, 65, 1);
border-color: #999999;
}
My problem is while "color: yellow" is applied, "background-color" is absolutely ignored.
I've inspected computed css in chrome, and seems it is right... but something is overrides my style!
How I must rewrite bootstrap in order to avoid this?

Just Added Parent class in css to override the default css.
In Below example only right navbar was override by css.
.nav.navbar-nav.navbar-right > li.dropdown.open,
.nav.navbar-nav.navbar-right > li.dropdown.open > a,
.nav.navbar-nav.navbar-right > li.dropdown.open > a:hover{
color: yellow;
background: #3da441;
border-color: #999999;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/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-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" 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>
<!-- 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>
</ul>
<ul class="nav navbar-nav navbar-right">
<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>
</ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>

I finally found the problem!
It was because background-image (included in bootstrap) imposed on background-color.
I've fixed adding this code to the component css file:
.navbar-default .navbar-nav > li > .dropdown-menu > li > a:hover,
.navbar-default .navbar-nav > li > .dropdown-menu > li > a:focus {
background-color: rgba(61, 164, 65, 0.1);
background-image: none;
}
.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 {
background-color: rgba(61, 164, 65, 0.1);
background-image: none;
}
.navbar-default .navbar-nav > .active > a,
.navbar-default .navbar-nav > .active > a:hover,
.navbar-default .navbar-nav > .active > a:focus {
background-color: rgba(61, 164, 65, 0.1);
background-image: none;
}
.navbar-default .navbar-nav > .open > a,
.navbar-default .navbar-nav > .open > a:hover,
.navbar-default .navbar-nav > .open > a:focus {
background-color: rgba(61, 164, 65, 0.1);
background-image: none;

Related

Change color of font in dropdown of bootstrap navbar when collapsed

I have been trying to change the color of the font shown in the image so that it is plainly visible.
this is a basic bootstrap 3 navbar. here is the html code
<nav class="navbar navbar-custom">
<div class="container">
<div class="container-fluid">
<div class="navbar-header">
<div class="navbar-spacer"></div>
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" 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 id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="first">Home</li>
<li class="dropdown ">
Item 1<span class="caret"></span>
<ul class="dropdown-menu">
<li>Item 1-1</li>
<li>Item 1-2</li>
<li>Item 1-3</li>
</ul>
</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
</ul>
</div>
</div>
</div>
</nav>
And this is what i have tried to do to change the font color
#media (max-width: 767) {
.dropdown-menu > li > a{
color: #ffffff !important;
}
.navbar-custom .container .container-fluid .navbar-nav .open .dropdown-menu > li > a {
color: #ffffff !important;
}
.navbar-custom .navbar-nav .open .dropdown-menu > li > a,
.navbar-custom .navbar-nav .open .dropdown-menu {
color: #ffffff !important;
}
.navbar-custom .navbar-nav .open .dropdown-menu > li > a:hover,
.navbar-custom .navbar-nav .open .dropdown-menu > li > a:focus {
color: #b0cb36;
background-color: transparent;
}
.navbar-custom .navbar-nav .open .dropdown-menu > .active > a,
.navbar-custom .navbar-nav .open .dropdown-menu > .active > a:hover,
.navbar-custom .navbar-nav .open .dropdown-menu > .active > a:focus {
color: #b0cb36;
background-color: #003748;
}
.navbar-custom .navbar-nav .open .dropdown-menu > .disabled > a,
.navbar-custom .navbar-nav .open .dropdown-menu > .disabled > a:hover,
.navbar-custom .navbar-nav .open .dropdown-menu > .disabled > a:focus {
color: #ffffff;
background-color: transparent;
}
}
Nothing I have tried has changed that dark font to be a lighter one
The main problem us with your media query - you need to include the unit e.g. #media (max-width: 767px)
Once that is corrected, you just need to use a more specific selector to override the Bootstrap CSS, rather than using !important. The selectors you need to override are:
.dropdown-menu>li>a
.dropdown-menu>li>a:focus, .dropdown-menu>li>a:hover
Adding the .navbar-nav class is enough, e.g. .navbar-nav .dropdown-menu>li>a - you don't want to make it too specific as it makes it more difficult if you wish to override it again in future.
Working example (except I've removed the collapse class so we can see it in the snippet)
#media (max-width: 767px) {
.navbar-nav .dropdown-menu>li>a {
color: red;
}
.navbar-nav .dropdown-menu>li>a:hover,
.navbar-nav .dropdown-menu>li>a:focus {
color: lime;
background-color: transparent;
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<nav class="navbar navbar-custom">
<div class="container">
<div class="container-fluid">
<div class="navbar-header">
<div class="navbar-spacer"></div>
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" 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 id="navbar" class="">
<ul class="nav navbar-nav">
<li class="first">Home</li>
<li class="dropdown ">
Item 1<span class="caret"></span>
<ul class="dropdown-menu">
<li>Item 1-1</li>
<li>Item 1-2</li>
<li>Item 1-3</li>
</ul>
</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
</ul>
</div>
</div>
</div>
</nav>
Add the class "text-danger" or whatever color you prefer. I didn't try it but I hope it works! If it does not work then add class to each li.
<nav class="navbar navbar-custom">
<div class="container">
<div class="container-fluid">
<div class="navbar-header">
<div class="navbar-spacer"></div>
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" 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 id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="first">Home</li>
<li class="dropdown ">
Item 1<span class="caret"></span>
<ul class="dropdown-menu text-danger">
<li>Item 1-1</li>
<li>Item 1-2</li>
<li>Item 1-3</li>
</ul>
</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
</ul>
</div>
</div>
</div>
</nav>

when i hover over bootstrap dropdown's each element does not occupy same background width

I am trying to create a dropdown list. I am not sure what is wrong with the code. When I hover over each list element it does not mark full width in red color.
here is the preview
Here is my HTML:
<!-- Navigation -->
<nav class="navbar navbar-custom">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" 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 class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li>
<a class="navbar-menu" href="#">Deals</a>
</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>
</ul>
</li>
</ul>
</div>
</div>
</nav>
Here is my CSS:
.navbar-custom {
background-color: #128C7E;
border-radius: 0px;
}
.navbar-custom a {
color: #ffffff;
}
.dropdown-menu > li > a:hover,
.dropdown-menu > li > a:focus {
background-image: none !important;
}
.dropdown-menu > li > a:hover,
.dropdown-menu > li > a:focus {
background-color: red;
}

Bootstrap 3 NavBar Move Link Underline Up

I built a standard fixed top navbar with a line height of 150 pixels for the desktop view of the site. Additionally I styled the links to have a red underline on hover but the underline is down at the bottom of the navbar rather than under the text.
I get that this is because of the line height but I'm wondering how to move it back up to just below the words.
Link to fiddle: JSFiddle link
Here is the CSS:
.navbar-brand,
.navbar-nav li a {
line-height: 150px;
height: 150px;
padding-top: 0;
background-color:#FFFFFF;
}
.navbar-default .navbar-nav > li > a:hover, .navbar-default .navbar-nav > li > a:focus { border-bottom:3px solid #9e1e22; }
The HTML:
<nav class="navbar navbar-default navbar-fixed-top">
<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="#topFixedNavbar1"><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="index.html">Brand</a></div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="topFixedNavbar1">
<ul class="nav navbar-nav navbar-right">
<li>About</li>
<li>News</li>
<li class="divider"></li>
<li>Assessments</li>
<li>Improvements</li>
<li>Incident Response</li>
<li class="divider"></li>
<li>Contact</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
Is this what you mean? Keep the NAV at 150 but the hover directly under the link.
#media (min-width: 768px) {
.navbar-default .navbar-brand,
.navbar-default .navbar-nav li a {
background-color: #FFFFFF;
}
.navbar-default .navbar-nav > li > a:hover,
.navbar-default .navbar-nav > li > a:focus {
border-bottom: 3px solid #9e1e22;
}
.navbar.navbar-default {
height: 150px;
padding-top: 45px;
}
}
.navbar.navbar-default {
background-color: #FFFFFF;
}
.navbar-default .navbar-nav > li > a:hover,
.navbar-default .navbar-nav > li > a:focus {
border-bottom: 3px solid #9e1e22;
}
<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.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-default navbar-fixed-top">
<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="#topFixedNavbar1"><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="index.html">Brand</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="topFixedNavbar1">
<ul class="nav navbar-nav navbar-right">
<li>About
</li>
<li>News
</li>
<li class="divider"></li>
<li>Assessments
</li>
<li>Improvements
</li>
<li>Incident Response
</li>
<li class="divider"></li>
<li>Contact
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
I know its not exactly what you after but rather than underlining the menu option, have you not thought of just changing the color of the menu option instead when hovered over.
.navbar-default .navbar-nav > li > a:hover,
.navbar-default .navbar-nav > li > a:focus
{
color: #9e1e22;
}

Remove blinking effet bootstrap dropdown

While modifying Bootstrap vanilla's css, I found a weird blinking effect when you click on a dropdown then click outside of it (in the body for example) :
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<style>
.navbar-default {
background-color: #222;
}
.navbar-default .navbar-brand,
.navbar-default .navbar-brand:hover,
.navbar-default .navbar-nav > li > a {
color: #FFF;
}
.navbar-default .navbar-nav > li > a:hover,
.navbar-default .navbar-nav > li > a:focus,
.navbar-default .navbar-nav > .dropdown > a:focus,
.navbar-default .navbar-nav > .open {
background-color: #444;
color: #FFF;
}
#media (min-width: 3000px) and (max-width: 3000px) {
.collapse {
display: none !important;
}
}
</style>
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<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" 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>
<!-- 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>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>
<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">
<li>Action
</li>
<li>Another action
</li>
<li>Something else here
</li>
<li role="separator" class="divider"></li>
<li>Separated link
</li>
</ul>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
To make the snippet actually displays the error, you need to see it within a full page.
I also made a JSFiddle to make things clearer, and less difficult to explain.
Do you have any idea about which css selector should I use to fix it ?
The element you need is the a.dropdown-toggle. I don't know how much specific is bootstrap when styling it, or even if it uses inline-style, but if you use !important you can see that the blinking stops.
.dropdown-toggle {
background-color: transparent !important;
}
Updated fiddle
Update:
Bootstrap uses: .nav .open>a, .nav .open>a:focus, .nav .open>a:hover
Check out with the below link and let me know if its working fine now.
https://jsfiddle.net/98o4kakg/3/
.navbar-default .navbar-nav > .open {
background-color: #444;
color:#FFF;
}
You need to style your dropdown link instead of the dropdown itself by adding this in your css :
.navbar-default .navbar-nav > .dropdown > a {
background-color:#222;
color:#FFF;
}
Including more tags and classes will hold a higher priority over a style on the same element without the extra classes.
For instance : just adding body before a class can make the class more specific.
I've updatded your JSFiddle as well.

CSS Selector Bootstrap navbar menu links

Bootstrap newb here. Having trouble finding the right selector to color the links in the menu. I've tried .nav a:link, a:hover but the hyperlink and hover color stays on the default blue/grey.
<div class="navbar navbar-static-top">
<div class="containerNav">
<div class="navbar-header"> Test
<button class="navbar-toggle" data-toggle="collapse" data-target=".navHeaderCollapse"> <span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse navHeaderCollapse">
<ul class="nav navbar-nav navbar-right">
<li class="active">Home
</li>
<li>Blog
</li>
<li class="dropdown"> Social media <b class = "caret"></b>
<ul class="dropdown-menu">
<li>Twitter
</li>
<li>Facebook
</li>
<li>Google+
</li>
<li>Instagram
</li>
</ul>
<li>About
</li>
<li>Contact
</li>
</ul>
</div>
<!-- end container -->
</div>
</div>
<!-- end nav bar -->
Using bootstrap 3.2. http://jsfiddle.net/nwjob2e0/ . (In JS fiddle my icon-bar is hidden under where it says 'result' so if youpress that the list should expand and you can see what I mean.
http://jsfiddle.net/nwjob2e0/#&togetherjs=ioVBLnT3mA - collab
Try this:
.navbar .navbar-nav > li > a {
color: #999;
}
And for Active, Hover, Focus:
.navbar .navbar-nav > li > a:hover,
.navbar .navbar-nav > li > a:focus {
color: #fff;
background-color: #000;
}
Update:
To modify dropdowns (like social media menu in your example):
.navbar .navbar-nav .open .dropdown-menu {
background-color: green;
}
.navbar .navbar-nav .open .dropdown-menu > li > a:hover,
.navbar .navbar-nav .open .dropdown-menu > li > a:focus {
background-color: red;
}
Check JSFiddle Demo
Update2:
Also you can use This Online Tool to generate a Bootstrap NavBar easily.

Resources