Remove blinking effet bootstrap dropdown - css

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.

Related

navbar dropdown menus display issue on mobile and small devices with media query

Not a big expert in CSS and responsiveness design, I try to collapse my navbar using a media query. The issue is that for dropdown menus, the responsive design is not applied correctl : The dropdown menus are displayed like on a large desktop device.
What I want is this :
Result Expected
But the result I obtain is this :
Current result
My code is actually the following :
<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>
And my media query is the current one as I found googling the web :
#media (max-width: 992px) {
.navbar-header {
float: none;
}
.navbar-left,.navbar-right {
float: none !important;
}
.navbar-toggle {
display: block;
}
.navbar-collapse {
border-top: 1px solid transparent;
box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
}
.navbar-fixed-top {
top: 0;
border-width: 0 0 1px;
}
.navbar-collapse.collapse {
display: none!important;
}
.navbar-nav {
float: none!important;
margin-top: 7.5px;
}
.navbar-nav>li {
float: none;
}
.navbar-nav>li>a {
padding-top: 10px;
padding-bottom: 10px;
}
.collapse.in{
display:block !important;
}
}
Additional info : The menu is displayed well when the viewport size is under 768px.
I guess, there is something missing on my media query for handling the dropdown menu case but I don't know what it is ? Can somebody help me ?
Thanks a lot.
here is your fiddle just remove default style dropdown
jsfiddle.net/qxgy6L9b/18/

How do I get full-height bootstrap nav buttons?

The default bootstrap nav does this when the screen is too small:
The gap beneath the 'Hotels' button shouldn't be there when I hover over the link, it's caused by the 'Private Hire' text being too long and pushing the nav down a bit.
Is there any way to get the white background to take up the full height of the nav?
I have been looking into the twitter bootstrap navbar and i found a way to get rid of that whitespace.
Quite simple....
.navbar-nav{
white-space: nowrap;
}
#media (min-width: 1200px){
.navbar-nav {
font-size: 22px;
}
}
#media (min-width: 994px) and (max-width: 1199px){
.navbar-nav {
font-size: 17px;
}
}
#media (max-width: 994px){
.navbar-nav {
font-size: 15px;
}
}
UPDATE 2:
Now I've got it. Please check this css code:
<style> a { color: #fff; }
.navbar {
background-color: #122B41 !important;
color: #fff;
height:100px; }
.navbar > div { height:100% !important; }
.navbar > div > div { height:100% !important; }
.navbar > div > div > ul { height:100% !important; }
.navbar > div > div > ul > li { height:100% !important; }
.navbar > div > div > ul > li > a { height:100% !important; }
.navbar-collapse.collapse { height:100% !important; } </style>
As I wrote in my UPDATE 1 statement, it's based on the default example of the bootstrap navbar.
Does this solve your problem?
UPDATE 1:
I've created a blank page, just with the default navbar example from the bootstrap page. I've just added some color via css (see style area) for better color display of the navbar. Here is the code of my default page:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"></meta>
<link rel="stylesheet" href="bootstrap.min.css"></link>
<link rel="stylesheet" href="bootstrap-theme.min.css"></link>
<link rel="stylesheet" href="bootstrap-theme.min.css.map"></link>
<style>
a {
color: #fff;
}
.navbar {
background-color: #122B41 !important;
color: #fff;
}
</style>
<script type="text/javascript" src="jquery-1.12.2.min.js"></script>
<script type="text/javascript" src="bootstrap.min.js"></script>
<script type="text/javascript" src="npm.js"></script>
</head>
<body>
<nav class="navbar navbar-primary">
<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>
<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">
<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>
</div>
</nav>
</body>
</html>
I'm wondering, because the default navbar, has exactly the desired "full-height". Please see my screenshot:
Maybe you provide the code of your navbar and additional css of your page?
ORIGINAL:
You can set the line-height property of the link accordingly to the height of your navbar via css.
.navbar-nav>li>a {
line-height: <height_of_your_navbar>px;
}

Why does bootstrap ignore some of my styles and accept others even when things are in the same class?

I'm using Angularjs and Bootstrap to make a web application and I'm using Bootstrap's nav navbar-nav navbar-inverse classes to set the styles for the navigation bar. I'm trying to change the way the menu options work when they are active.
I've added this to my css file
.navbar-nav li.active {
background-color: red;
text-decoration: underline;
height:40px;
}
The problem is that I only see some of the changes. When a menu option is active the text is now underlined, but the color is still the same color as before and the height is unchanged.
Why does bootstrap use some CSS while ignoring other things when they are in the same class?
When you rewrite something already defined in your bootstrap css included file or defined somewhere else you have to add !important at the end of thr css rule to make the desired css take priority over the other definitions.
To change the color refer to the lowest element before text, in this case use the selector:
.navbar-default .navbar-nav > .active > a, .navbar-default .navbar-nav > .open > a
.navbar-nav li.active {
background-color: red;
text-decoration: underline;
height:158px !important;
}
.navbar-default .navbar-nav > .active > a, .navbar-default .navbar-nav > .open > a {
background-image: none !important;
background-color: blue !important;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap-theme.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/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">
<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>

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.

style single bootstrap 3 nav dropdown link

I have the following Bootstrap3 Nav menu (fiddle here). I'd like to style the link text (and hover) of the 'Highlight' item as well its child links differently from the dropdown 1 and 2 links. I'd also like to be able to style the child links (and hover) differently from the Highlight parent link. I can style the background (as shown), but I haven't been able to find the correct style for the links. Suggestions?
My HTML:
<div class="container">
<!-- Static navbar -->
<div class="navbar navbar-inverse" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<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="#">Project name</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="dropdown">
Dropdown 1<b class="caret"></b>
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
</ul>
</li>
<li class="dropdown">
Dropdown 2<b class="caret"></b>
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
</ul>
</li>
<li class="dropdown highlight">
Highlight<b class="caret"></b>
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
</ul>
</li>
</ul>
</div><!--/.nav-collapse -->
</div><!--/.container-fluid -->
</div>
</div> <!-- /container -->
My CSS:
![#import url('http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css');
.highlight{ background-color:#eeaf41;}
.highlight a {
font-weight:bold;
}
.highlight a:hover {
background-color:#FFA;
}.highlight a:active {
position:relative;
top:1px;
color:#999;
}
.dropdown-menu li a {color:#900000}][2]
Here are a few selectors you can choose from. They ensure that the other styling will be overwritten by taking the specificity into account. Additionally, they make use of the child combinator, >, in order to style only the direct sibling elements (in case more are nested).
Example Here
Selector for the .highlight element when open/closed, respectively:
.nav.navbar-nav .highlight.open > a,
.highlight {
/* ... */
}
Selector for the .highlight element on hover:
.nav.navbar-nav .highlight > a:hover {
/* ... */
}
Selector for the direct child ul element (submenu elements):
.nav.navbar-nav .highlight > ul {
/* ... */
}
Selector for styling the submenu elements on hover:
.navbar-nav .highlight.open .dropdown-menu > li > a:hover {
/* ... */
}

Resources