bootstrap border-bottom links only text - css

I have this menu :
<div class="navbar navbar-custom navbar-fixed-top">
<div class="container">
<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="/">MyWeb</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>Home</li>
<li>Features</li>
<li>Downloads</li>
<li>About</li>
<li>FAQ</li>
<li>Contact</li>
</ul>
</div>
</div>
Now I try to make a custom underline of 4 pixels but only for the text.
I tried this :
navbar-custom .navbar-nav > li > a {
border-bottom : 4px solid black ;
}
but then the border-bottom takes the whole space
How can I make it work so only the text is underlined not the whole li ?

You can do this:
CSS:
<style>
navbar-custom .navbar-nav > li > a {
display: inline-block;
max-width: 100px;
text-decoration: none;
}
span {
border-bottom: 4px solid;
}
</style>
HTML:
<li><a href='#'><span>Home</span></a></li>

see here
jsfiddle
well with bootstrap a has the padding so if you want to add the border to a and the a not to be as wide as the li , remove padding from a and add padding to li
CSS
.navbar-custom .navbar-nav > li > a {
border-bottom : 4px solid black ;
padding:0;
}
.navbar-custom .navbar-nav > li {
padding:15px;
}

Related

Bootstrap Navigation - Space Between Menu Items

I have the following Bootstrap navigation set up. I want to reduce the space between each li in the ul under the "Coverage" dropdown-toggle. What setting do I use to do this? As a side note, when I set float: left on the ul li a, the space is reduced, but I don't need float to do this. Why does it reduce the space though?
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand mycontent5" href="/?goHome=true"><span class="glyphicon glyphicon-home"></span></a>
<button type="button" data-toggle="collapse" data-target=".navbar-collapse" class="navbar-toggle">
<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 navbar-left">
<ul class="nav navbar-nav">
<li>Analysts</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Coverage<span class="caret"></span></a>
<ul class="dropdown-menu" id="mynavlist">
<li>All Coverage</li>
<li>Coverage Assignments</li>
<li>Portfolio Coverage</li>
<li>Portfolio Snapshot</li>
<li>Writeup Sections</li>
</ul>
</li>
<li>Funds</li>
<li>Intraday Orders</li>
<li>Reports</li>
</ul>
</div>
</nav>
EDIT: I changed my ul to have an id of "mynavlist", and added the following CSS:
#mynavlist li a {
padding-top: 0px !important;
padding-bottom: 0px !important;
margin-top: 0px !important;
margin-bottom: 0px !important;
}
This results in the following: I want to get rid of all white space above and below each item. Increasing the px sizes changes my list as expected, but how can I get rid of the extra space?
You have to reduce the top and bottom padding of each item. Try below css
.navbar-default .dropdown-menu>li>a {
padding: 0 20px;
}
/*For responsive*/
#media (max-width: 767px) {
.navbar-default .navbar-nav .open .dropdown-menu>li>a {
padding: 0 20px;
}
}
.navbar-default .dropdown-menu>li>a {
padding: 0 20px;
}
/*For responsive*/
#media (max-width: 767px) {
.navbar-default .navbar-nav .open .dropdown-menu>li>a {
padding: 0 20px;
}
}
<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" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand mycontent5" href="/?goHome=true"><span class="glyphicon glyphicon-home"></span></a>
<button type="button" data-toggle="collapse" data-target=".navbar-collapse" class="navbar-toggle">
<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 navbar-left">
<ul class="nav navbar-nav">
<li>Analysts</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Coverage<span class="caret"></span></a>
<ul class="dropdown-menu">
<li>All Coverage</li>
<li>Coverage Assignments</li>
<li>Portfolio Coverage</li>
<li>Portfolio Snapshot</li>
<li>Writeup Sections</li>
</ul>
</li>
<li>Funds</li>
<li>Intraday Orders</li>
<li>Reports</li>
</ul>
</div>
</nav>
If you use your browsers Console or Inspector you can view each HTML element and any CSS that is being applied to that element. In the case of Bootstrap's Navbar component you will find the following:
.navbar-nav > li > a {
padding-top: 15px;
padding-bottom: 15px;
}
Changing 15px to some other value will result in your desired output, though you should note that Bootstrap modifies the top and bottom padding for this element based on certain media breakpoints: you will need to account for this in your customizations.

Bootstrap navbar collapsing upon clicking an option

I've been trying to figure this out for a while now but I can't seem to be able to locate the problem. Whenever I click on an option from the navbar, it collapses to mobile size (currently set to 992px in bootstrap so its available on tablets), and then return to original size, which turns out that it has a height of 80px after inspecting it. It used to be fine before, but it has suddenly changed after some code edits. I have included some pictures of the problem below.
HTML:
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<!-- Navigation logo and dropdown icon -->
<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="#"><img src="css/logo-dream.png" id="logo"></img></a>
</div>
<!-- Navigation Options -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right" id="nav-appearance">
<li id="main-nav">Home <span class="sr-only">(current)</span></li>
<li id="main-nav">About Us</li>
<li id="main-nav">Services</li>
<li id="main-nav">Gallery</li>
<li>Contact</li>
</ul>
</div>
</div>
</nav>
Below is the CSS code I have used:
/* Main navbar design */
.navbar {
border-radius: 0px;
opacity: 0.95;
background-color: #171717;
border-bottom: 1px solid #9494b8;
margin-bottom: 0 !important;
}
.navbar .navbar-nav {
margin: 15px 0;
}
/* Navbar company logo */
.navbar-brand {
padding: 0;
}
#logo {
margin-left: 40px;
width: 171px;
height: 66px;
margin-top: 8px;
}
/* Navbar options */
#nav-appearance {
font-size: 1.7rem;
margin-right: 40px;
font-family: 'Quicksand', sans-serif;
}
#nav-appearance li {
padding-left: 35px;
}
.collapse {
padding: 0;
}
.navbar-collapse {
padding: 0;
}
/* ======= MEDIA QUERIES FOR NAVIGATION AND HOME ======= */
/* Tablets */
#media (max-width: 991px) {
#nav-appearance {
font-size: 1.7rem;
margin-right: 10px;
}
#nav-appearance a {
padding: 0;
}
#nav-appearance li {
padding: 15px 0 15px 0;
width: 80%;
transform: translateX(-50%);
top: 0;
left: 52%;
}
#main-nav {
border-bottom: 1px solid rgba(55, 55, 55, .95);
}
#logo {
content:url("home-icon-tiny.png");
height: 34px;
width: 34px;
margin-left: 13px;
}
}
/* Mobile */
#media (max-width: 767px) {
#logo {
margin-left: 13px;
}
}
Can anyone see any issues? I hope it's an easy fix.
Update:
From the page its clear that one of the JS files is interfering with the navbar elements. By setting some CSS we can remove the height change, please find below the CSS.
Codepen: here
CSS:
.navbar-brand img{
margin-top:7px;
margin-bottom:7px;
}
/* Navbar company logo */
.navbar-brand {
padding: 0;
height:100%;
}
HTML:
<!-- Navigation logo and dropdown icon -->
<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="#"><img src="css/logo-dream.png" id="logo"></img></a>
</div>
<!-- Navigation Options -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right" id="nav-appearance">
<li id="main-nav">Home <span class="sr-only">(current)</span></li>
<li id="main-nav">About Us</li>
<li id="main-nav">Services</li>
<li id="main-nav">Gallery</li>
<li>Contact</li>
</ul>
</div>
</div>
</nav>
From the images given I would say that this is a floating elements not having height issue, the solution for this is the clearfix class. so if you change the code as shown below it should not happen. also I removed the div with container-fluid class.
Code: (Do not use)
<!-- Navigation logo and dropdown icon -->
<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="#"><img src="css/logo-dream.png" id="logo"></img></a>
</div>
<!-- Navigation Options -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right" id="nav-appearance">
<li id="main-nav">Home <span class="sr-only">(current)</span></li>
<li id="main-nav">About Us</li>
<li id="main-nav">Services</li>
<li id="main-nav">Gallery</li>
<li>Contact</li>
</ul>
</div>

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;
}

Transparent Fixed-top Navbar with Boostrap

HTML:
<nav class="navbar navbar-default navbar-fixed-top navbar-transparent">
<div class="container">
<div 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 class="navbar-brand" href="#">Project name</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li class="active">Home</li>
<li>About</li>
<li>Contact</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
Custom CSS (other than the base bootstrap CSS):
.navbar-transparent {
background:transparent;
background-image: none;
border-color: transparent;
}
I looked at other posts on Stack Overflow and here and there on Google, but I can't seem to find a way to make the navbar fully transparent.
So far it looks like this and surely there must be an easier way to set the navbar transparent than to have to edit for all the classes and sub classes and elements within those classes manually?
I guess this works. If anyone has a better workaround, please answer.
#media screen and (min-width: 680px) {
.navbar-transparent {
background: transparent;
background-image: none;
border-color: transparent;
}
.navbar-default .navbar-nav>.active>a,
.navbar-default .navbar-nav>.active>a:focus,
.navbar-default .navbar-nav>.active>a:hover {
background: transparent;
background-image: none;
border-color: transparent;
}}
You have to overwrite the ".active" class in your css.
You are already using that (predefined bootstrap) css-class in your code:
< li class="active">< a href="#">Home< / a >< / li>
try:
#navbar ul li.active {
background:transparent;
background-image: none;
border-color: transparent;
}
#navbar ul li:hover { // to overwrite when you :hover the list items
background:transparent;
background-image: none;
border-color: transparent;
}

Bootstrap navbar-fixed-top breaks when increasing height

So I have a navbar-fixed-top that's set to collapse at 992px, most mobile screens wont collapse at anything lower than that anymore. Well, from what I can tell anyway. The problem is that when I try increase the navbar height at the lower screen width, I cant vertically center anything on the navbar - being the placeholder for the logo to come or the dropdown button. I'm also struggling to increase the size of the dropdown button no matter what I try. Finally as soon as I increase the height of the navbar, when I click the dropdown menu, the background image disappears yet it works fine with the default height. I'm really hoping someone knows a trick or two as it seems lots of people are struggling with navbar-fixed-top.
Here's the html setup:
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="#">Logo</a>
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#collapsed-navbar">
<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="collapsed-navbar">
<ul class="nav navbar-nav">
<li><a ng-href="#link">Link 1</a></li>
<li><a ng-href="#link">Link 2</a></li>
<li><a ng-href="#link">Link 3</a></li>
<li><a ng-href="#link">Link 4</a></li>
<li class="divider"></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><img class="img-circle nav-profile-image" src="images/default_pic.png" /></li>
<li><a ng-href="#link">Profile</a></li>
<li>Logout</li>
</ul>
</div>
</div>
</nav>
And here's the CSS so far:
#media (max-width: 992px) {
.nav-profile-image {
display: none;
}
.navbar {
height: 80px;
font-size: 24px;
}
}
#media (min-width: 992px) {
.nav-profile-image {
height: 40px;
margin-top: 5px;
}
}
.navbar {
background-image: url('../images/noise-background.jpg');
background-color: #F8F8F8;
}
.navbar-default .navbar-nav > li > a:hover {
color: #555;
background-color: #E7E7E7;
opacity: 0.6;
}
.navbar-default .navbar-nav > .active > a:hover {
color: #555;
background-color: #E7E7E7;
opacity: 1;
}
Thanks in advance!

Resources