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.
Related
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>
I'm using Bootstrap 4 and created a simple navbar (here is the CodePen). My active li looks the way I like with a square orange background. However, when I hover over the other li's, the :hover ones are not as tall.
I want the hovers to be just like the active--orange and same size. I've used the inspector to try and figure out where the sizing is coming from but can't find anything that changes it. How do I fix that?
HTML
<header>
<!-- Navigation -->
<nav class="navbar navbar-expand-lg navbar-custom">
<div class="container">
<a class="navbar-brand" href="#"><img src="https://s3.amazonaws.com/listing-naples/assets/listing-naples-logo.png" alt="Listing Naples Team Logo"></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="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Properties</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Property</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Agents</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Agencies</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">News</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Pages</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<input class="form-control-sm mr-sm-2 custom-input-sm" type="search" placeholder="MLS Number" aria-label="Search">
</form>
</div><!-- end collapse navbar-collapse div-->
</div><!-- end container div -->
</nav>
</header>
CSS
body {
font-family: 'Source Sans Pro', sans-serif;
}
.navbar-custom {
background-color:#000;
padding: 1.5rem;
}
header li {
padding: .5rem;
margin:0;
}
.navbar-custom .navbar-brand,
.navbar-custom .navbar-text {
color: rgba(255,255,255,.8);
}
/* change the link color */
.navbar-custom .navbar-nav .nav-link {
color: rgba(255, 255, 255, 0.5);
font-weight:400;
font-size: 1rem;
}
/* change the color of active or hovered links */
.navbar-custom .nav-item.active .nav-link,
.navbar-custom .nav-item:focus .nav-link,
.navbar-custom .nav-item:hover .nav-link {
color: white;
background-color: orange;
}
.active {
background-color: orange;
}
From your CSS code
.navbar-custom .nav-item:hover .nav-link
you are setting the background-color to orange of nav-link which is the anchor tag
While this line
.active {
background-color: orange;
}
sets the background-color of the li tag
You can fix this problem by deleting
.active {
background-color: orange;
}
This adds it to the a element
.navbar-custom .nav-item.active .nav-link,
.navbar-custom .nav-item:focus .nav-link,
.navbar-custom .nav-item:hover .nav-link {
color: white;
background-color: orange;
}
And this adds it to the li element
.active {
background-color: orange;
}
It is because of this code
header li {
padding: .5rem;
margin: 0;
}
it is setting the padding of .5 rem to the block.
set your changing values on hover to element itself. For further issues try reading the code of css libraries you are using.
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;
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;
}
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.