Bootstrap navtab hover does not cover full tab - hover

I'm using bootstrap nav tab to make the main page tabs.
I made it in a way that when a user hover the mouse over any tab, it changes color. The problem that I'm having right now is that the hover does not cover the entire range of each tab. I looked around webs to solve this issue but I wasn't able to address this issue.
HTML
<header>
<a href="#">
<img src="../static/img/the_logo_original_fixed.jpg" style="width: 140px;height:100px;" class="the_logo">
</a>
<nav class="navbar navbar-light bg-faded">
<ul class="nav nav-tabs" style="border-bottom:0px">
<li class="nav-item">
<a class="nav-link" href="#">Services</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Support</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact</a>
</li>
</ul>
</nav>
</header>
CSS
.the_logo{
margin-top: 20px;
margin-bottom: 20px;
}
nav.navbar.navbar-light.bg-faded{
background-color: #3081B7;
}
a{
color: white !important;
font-size: 120%;
}
.nav.nav-tabs > li > a:hover,
.nav.nav-tabs > li > a:active,
.nav.nav-tabs > li > a:focus{
background-color: #5FA6D5 !important;
border: none;
color: #5FA6D5;
}

Try adding the hover functionality to the list item not to the anchor tag because the anchor tag is smaller it only covers the text area.

Related

How to change border color of nav-tab?

I'm having trouble changing the border color for Tab 2 (see below). For Tab 1, the color changes from the default light gray color.
My custom CSS is placed after the bootstrap 5 CSS so it should be overwriting my changes without issue. What am I doing wrong here?
CSS
.nav-tabs {
border-color: black;
}
.nav-tabs > li > a {
border-color: red;
}
.nav-tabs > li > a:hover {
border-color: blue;
}
.nav-tabs > li.active > a {
border-color: green;
}
HTML
<ul class="nav nav-tabs mb-5">
<li class="nav-item active">
<a class="nav-link" href="#">Tab 1</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Tab 2</a>
</li>
</ul>
There are a few problems...
The active class doesn't automatically change using just HTML markup. Use the Tabs javascript component. For example data-bs-toggle="tab"...
<ul class="nav nav-tabs mb-5">
<li class="nav-item">
<a class="nav-link active" href="#t1" data-bs-toggle="tab">Tab 1</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#t2" data-bs-toggle="tab">Tab 2</a>
</li>
</ul>
Secondly, the active class goes on the nav-link not the nav-item. So the CSS selector would be...
.nav-tabs > li > .nav-link.active {
border-color: green;
}
https://codeply.com/p/EtmicwumKC

Why are my navbar links appearing vertically rather than horizontal?

My nav links are appearing like so:
/* You can add global styles to this file, and also import other style files */
#import '#angular/material/prebuilt-themes/deeppurple-amber.css';
#import 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css';
mark {
background-color: yellow !important;
color: black;
}
.navbar-custom {
background-color: #4082e485;
}
/* change the brand and text color */
.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,.5);
}
/* change the color of active or hovered links */
.navbar-custom .nav-item.active .nav-link{
color: #ffffff !important;
}
.navbar-custom .nav-item:hover .nav-link {
color: blue !important;
}
<nav class="navbar navbar-custom">
<div class="container" id="navbarNav">
<a class="navbar-brand" routerLinkActive="active" [routerLink]="['/']"><fa-icon [icon]="faGlobeAmericas"></fa-icon> Offshore</a>
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" routerLinkActive="active" [routerLink]="['/']"><fa-icon [icon]="faHome"></fa-icon> Home</a>
</li>
<li class="nav-item active">
<a class="nav-link" routerLinkActive="active" [routerLink]="['/results']" ><fa-icon [icon]="faSearch"></fa-icon> Search</a>
</li>
<li class="nav-item active">
<a class="nav-link" routerLinkActive="active" [routerLink]="['/links']" ><fa-icon [icon]="faLink"></fa-icon> Links</a>
</li>
</ul>
</div>
</nav>
Rather than side by side.
Anyone know how to
Fix this so that the links appear horizontally.
The colour of the nav links do change when I hover over them, however they don't reflect the page I'm currently on - so it would be a great if I could have this working too.
you just have to add nav class to <ul class="navbar-nav"> your problem will solve.
#import '#angular/material/prebuilt-themes/deeppurple-amber.css';
#import 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css';
mark {
background-color: yellow !important;
color: black;
}
.navbar-custom {
background-color: #4082e485;
}
/* change the brand and text color */
.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,.5);
}
/* change the color of active or hovered links */
.navbar-custom .nav-item.active .nav-link{
color: #ffffff !important;
}
.navbar-custom .nav-item:hover .nav-link {
color: blue !important;
}
<nav class="navbar navbar-custom">
<div class="container" id="navbarNav">
<a class="navbar-brand" routerLinkActive="active" [routerLink]="['/']"><fa-icon [icon]="faGlobeAmericas"></fa-icon> Offshore</a>
<ul class="navbar-nav nav">
<li class="nav-item active">
<a class="nav-link" routerLinkActive="active" [routerLink]="['/']"><fa-icon [icon]="faHome"></fa-icon> Home</a>
</li>
<li class="nav-item">
<a class="nav-link" routerLinkActive="active" [routerLink]="['/results']" ><fa-icon [icon]="faSearch"></fa-icon> Search</a>
</li>
<li class="nav-item">
<a class="nav-link" routerLinkActive="active" [routerLink]="['/links']" ><fa-icon [icon]="faLink"></fa-icon> Links</a>
</li>
</ul>
</div>
</nav>
Note: make snippet full width and check it will work perfect. if you want to make all the link in same line in small devices also you need to make media css for that.
I hope this will help you.
Thank You...
Try inline-block on li
/* You can add global styles to this file, and also import other style files */
#import '#angular/material/prebuilt-themes/deeppurple-amber.css';
#import 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css';
mark {
background-color: yellow !important;
color: black;
}
.navbar-custom {
background-color: #4082e485;
}
/* change the brand and text color */
.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,.5);
}
/* change the color of active or hovered links */
.navbar-custom .nav-item.active .nav-link{
color: #ffffff !important;
}
.navbar-custom .nav-item:hover .nav-link {
color: blue !important;
}
.nav-item{
display: inline-block;
margin-right: 10px;
}
<nav class="navbar navbar-custom">
<div class="container" id="navbarNav">
<a class="navbar-brand" routerLinkActive="active" [routerLink]="['/']"><fa-icon [icon]="faGlobeAmericas"></fa-icon> Offshore</a>
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" routerLinkActive="active" [routerLink]="['/']"><fa-icon [icon]="faHome"></fa-icon> Home</a>
</li>
<li class="nav-item active">
<a class="nav-link" routerLinkActive="active" [routerLink]="['/results']" ><fa-icon [icon]="faSearch"></fa-icon> Search</a>
</li>
<li class="nav-item active">
<a class="nav-link" routerLinkActive="active" [routerLink]="['/links']" ><fa-icon [icon]="faLink"></fa-icon> Links</a>
</li>
</ul>
</div>
</nav>
And second for second try this RouterLink does not work
It is because the default behaviour of an unordered list ( <ul><li></li></ul> ) is to stack vertically. One way to style this differently is by making its parent flex and justify it's child elements in a way you prefer. In the following example this has been done with flex:
.navbar-custom {
background-color: #4082e485;
}
.navbar-custom .navbar-brand,
.navbar-custom .navbar-text {
color: rgba(255,255,255,.8);
}
.navbar-custom .navbar-nav .nav-link {
color: rgba(255,255,255,.5);
}
.navbar-custom .nav-item.active .nav-link{
color: #ffffff !important;
}
.navbar-custom .nav-item:hover .nav-link {
color: blue !important;
}
/* added code to make the navigation horizontal */
#navbarNav {
display: flex;
justify-content: center;
align-items: center;
}
.navbar-nav {
display: flex;
justify-content: space-evenly;
}
.navbar-nav li {
list-style-type: none;
padding: 0 15px;
}
<nav class="navbar navbar-custom">
<div class="container" id="navbarNav">
<a class="navbar-brand" routerLinkActive="active" [routerLink]="['/']"><fa-icon [icon]="faGlobeAmericas"></fa-icon> Offshore</a>
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" routerLinkActive="active" [routerLink]="['/']"><fa-icon [icon]="faHome"></fa-icon> Home</a>
</li>
<li class="nav-item active">
<a class="nav-link" routerLinkActive="active" [routerLink]="['/results']" ><fa-icon [icon]="faSearch"></fa-icon> Search</a>
</li>
<li class="nav-item active">
<a class="nav-link" routerLinkActive="active" [routerLink]="['/links']" ><fa-icon [icon]="faLink"></fa-icon> Links</a>
</li>
</ul>
</div>
</nav>
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#main_nav">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="main_nav">
<ul class="navbar-nav">
<li class="nav-item active"> <a class="nav-link" href="#">Home </a> </li>
<li class="nav-item"><a class="nav-link" href="#"> About </a></li>
<li class="nav-item"><a class="nav-link" href="#"> Services </a></li>
</ul>
</div> <!-- navbar-collapse.// -->
</nav>
Here are more examles of navbars
Navbar
Home
About
Services
Here are more examles of navbars https://bootstrap-menu.com/index.html

Alignment of collapsed menu on hover

I have been trying to wrap my head around this issue for over an hour now and can't seem to fix.
When my nav menu collapses and I hover mouse over the SHOP item in menu, it moves the SHOP element to the left. When I mouse away, it goes back to middle position. SHOP should stay in line with the other two menus (NOT move left)
I have tried adjusting the dropdown-menu class as well as CSS for dropdown but still no fix.
Any push in right direction is appreciated. Thanks
HTML:
<div class="collapse navbar-collapse nav-layout" id="navbarNavDropdown">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="index">HOME</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle"dropdown" aria-haspopup="true" aria-expanded"false">SHOP</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" href="products">Tealights</a>
<a class="dropdown-item" href="products">Wax-Melts<span class="sr-only">(current)</span></a>
<a class="dropdown-item" href="products">Medium Candle</a>
<a class="dropdown-item" href="products">Large Candle</a>
<a class="dropdown-item" href="products">X-Large Candle</a>
</div>
</li>
<li>
<a class="nav-link" href="contact">CONTACT</a>
</li>
</ul>
</div>
</nav>
CSS:
.narbar-default .navbar-nav > li.dropdown:hover > a,
.narbar-default .navbar-nav > li.dropdown:hover > a:hover,
.narbar-default .navbar-nav > li.dropdown:hover > a:focus, {
color: rgb(100, 100, 100);
}
.dropdown:hover > .dropdown-menu {
display: block;
background-color: #909090;
}
What displays on screen when hover over SHOP dropdown
You need to add position:absolute to teh dropdown-menu selector. Try this code.
.dropdown {
position: relative;
}
.dropdown > .dropdown-menu {
position: absolute;
left: 0;
top: 100%;
z-index: 2;
}

Bootstrap Menu Tabs "Jump" on mobile and tablet

I'm using Bootstrap to develop a menu for a client, but for some reason when I click certain tabs in mobile or tablet mode, the tabs "jump" to another location on the list and leaves an ugly space in between tabs. I made a .gif to show what I'm talking about.
Any ideas why this is happening? I included my own HTML and CSS below. Keep in mind I'm using Bootstrap CSS and JS as well.
EDIT: I think it may have to do something with floats.
<ul class="nav nav-tabs" role="tablist">
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#waxing" role="tab"> WAXING </a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#nail-art" role="tab"> NAIL ART </a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#nail-enchancements" role="tab">
<div class="hidden-xs"> NAIL ENCHANCEMENTS </div>
<div class="hidden-sm hidden-md hidden-lg hidden-xl"> NAIL ENH </div>
</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#children" role="tab"> FOR CHILDREN </a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#vitamin-dip" role="tab"> VITAMIN DIPS </a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#gel-services" role="tab"> GEL SERVICES </a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#combo-services" role="tab"> COMBINATIONS </a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#pedicure" role="tab"> PEDICURES </a>
</li>
<li class="nav-item">
<a class="nav-link active" data-toggle="tab" href="#manicure" role="tab"> MANICURES </a>
</ul>
CSS
.nav-tabs{
background-color:#fff;
border-radius: 3px 6px 0px 0px;
}
.nav-tabs > li {
float: right;
margin-bottom: -1px;
background-color: #fff;
margin:auto;
}
#media(max-width:992px){
.nav-tabs > li {
width:50%;
}
}
.nav-tabs > li.active > a:focus, .nav-tabs > li.active {
border-bottom-style:none;
border-bottom-width: 0px;
background-color: #d3d3d3;
margin-bottom: -1px;
}
#menu-tabs .nav-link{
font-weight: bold;
color: #000;
font-size: 0.8em;
}
#waxing li, #other li {
line-height: 23px;
}
I solved my problem. I did it by explicitly setting the height of each li.
#media(max-width:992px){
.nav-tabs > li {
height: 37px;
width:50%;
text-align:center;
}
}
I think my problem was that I assumed all the li will keep the same height when I click on the link (focus on the a tag) within each li. I know using the float property on elements that are not the same width and height may cause gaps between the elements, hence the ugly gaps and jumps in my original code.

Centering navbar links in bootstrap

I want to center my links on mobile view (md and down view) of my navbar but I can't seem to find a solution for it. I am using bootstrap v4-alpha
<div class="container-fluid p-b-3">
<nav class="navbar navbar-full navbar-fixed-top navbar-light bg-faded">
<ul class="nav navbar-nav">
<li>
<a class="nav-item nav-link pull-xs-right m-l-2 font-weight-bold" data-toggle="modal" data-target="#myModal" style="cursor:pointer;">LINK 3</a>
</li>
<li>
<a class="nav-item nav-link pull-xs-right m-l-2 font-weight-bold" href="#kontakti">LINK 2</a>
</li>
<li>
<a class="nav-item nav-link pull-xs-right m-l-2 font-weight-bold" href="#produktet">LINK 1</a>
</li>
</ul>
</nav>
</div>
Here's the codepen link
You can achieve it using flexbox.
Here's a working pen I created: http://codepen.io/anon/pen/bwbpNx
CSS
.navbar-nav {
display: flex;
align-items: center;
justify-content: center;
}
I think this is one of the proper way to do it. So that, if you add another link. It will remain at center. Hope it helps. Cheers!
Use media query and override styles to make your links center aligned.
#import url('https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.3/css/bootstrap.min.css');
#media (max-width: 767px) {
.navbar ul {
text-align: center;
}
.navbar ul li {
display: inline-block;
vertical-align: top;
padding: 0 10px;
}
.navbar ul li a {
margin-left: 0 !important;
}
}
<div class="container-fluid p-b-3">
<nav class="navbar navbar-full navbar-fixed-top navbar-light bg-faded">
<ul class="nav navbar-nav">
<li>
<a class="nav-item nav-link pull-xs-right m-l-2 font-weight-bold" data-toggle="modal" data-target="#myModal" style="cursor:pointer;">LINK 3</a>
</li>
<li>
<a class="nav-item nav-link pull-xs-right m-l-2 font-weight-bold" href="#kontakti">LINK 2</a>
</li>
<li>
<a class="nav-item nav-link pull-xs-right m-l-2 font-weight-bold" href="#produktet">LINK 1</a>
</li>
</ul>
</nav>
</div>