Bootstrap Menu Tabs "Jump" on mobile and tablet - html

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.

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

how to solve difference color for same component in scss?

How to solve difference colors for a same component in scss?
For example, border-bottom of nav-item sometimes I will use #F57C00 but sometimes will use #FF5252. I have three colors want to display based on different places in a website. How can I easy to make it? Thanks.
HTML
<div class="tab-content" id="myTabContent">
<ul class="nav nav-tabs" id="myTab" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="home-tab" data-toggle="tab" href="#contact" role="tab" aria-controls="contact" aria-selected="true">A</a>
</li>
<li class="nav-item">
<a class="nav-link" id="contact-tab" data-toggle="tab" href="#home" role="tab" aria-controls="home" aria-selected="false">B</a>
</li>
<li class="nav-item">
<a class="nav-link" id="profile-tab" data-toggle="tab" href="#profile" role="tab" aria-controls="profile" aria-selected="false">C</a>
</li>
<li class="nav-item">
<a class="nav-link" id="contact-tab" data-toggle="tab" href="#contact" role="tab" aria-controls="contact" aria-selected="false">D</a>
</li>
<li class="nav-item">
<a class="nav-link" id="contact-tab" data-toggle="tab" href="#contact" role="tab" aria-controls="contact" aria-selected="false">E</a>
</li>
</ul>
</div>
SCSS
.tab-container {
margin: 5px;
padding: 5px 0px;
color: #000000;
font-size: 14px;
height: 100%;
// border-style: dashed;
// border-color: #F57C00;
p {
margin: 0;
}
h2 {
font-size: 18px;
font-weight: bold;
}
.nav-tabs>.active>a, .nav-tabs>.active>a:hover, .nav-tabs>.active>a:focus {
border-color: #F57C00;
border-bottom-color: transparent;
}
.nav-tabs {
border-bottom: 1px solid #F57C00;
font-weight: bold;
}
.nav-item {
.active {
border-width: 1px;
color: #F57C00;
border-style: solid;
border-color: #F57C00;
}
}
}
//You can use three variables for colors so you just need to change in variables to change colors,
$primary-color:#F57C00;
$secondary-color:#FF5252;
.tab-container {
margin: 5px;
padding: 5px 0px;
color: #000000;
font-size: 14px;
height: 100%;
.nav-tabs > .active > a,
.nav-tabs > .active > a:hover,
.nav-tabs > .active > a:focus {
border-color: #F57C00;
border-bottom-color: transparent;
}
.nav-tabs {
border-bottom: 1px solid #F57C00;
font-weight: bold;
}
.nav-item {
a {
display: block;
float: left;
background: #ddd;
padding: 10px;
width: 80%;
}
.active {
border-width: 1px;
color: $primary-color;
border-style: solid;
border-color: $primary-color;
}
}
}
<div class="tab-container">
<div class="tab-content" id="myTabContent">
<ul class="nav nav-tabs" id="myTab" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="home-tab" data-toggle="tab" href="#contact" role="tab" aria-controls="contact" aria-selected="true">A</a>
</li>
<li class="nav-item">
<a class="nav-link" id="contact-tab" data-toggle="tab" href="#home" role="tab" aria-controls="home" aria-selected="false">B</a>
</li>
<li class="nav-item">
<a class="nav-link" id="profile-tab" data-toggle="tab" href="#profile" role="tab" aria-controls="profile" aria-selected="false">C</a>
</li>
<li class="nav-item">
<a class="nav-link" id="contact-tab" data-toggle="tab" href="#contact" role="tab" aria-controls="contact" aria-selected="false">D</a>
</li>
<li class="nav-item">
<a class="nav-link" id="contact-tab" data-toggle="tab" href="#contact" role="tab" aria-controls="contact" aria-selected="false">E</a>
</li>
</ul>
</div>
Please refer link to see demo,
https://jsfiddle.net/jignashagpatel/ydjx08vg/16/
You can make use of variables in SCSS to store colours.
They can then be used without having to mention the hex each and every time.
It'll also help keep the code maintainable incase you wanna change a color in the future , you can just change the color assigned to the variable.

Bootstrap 4 tabs multi-level tablist with collapse is not working properly; more than one tab active at the same time

li.nav-item { display: block; width: 100%; position: relative; display: lock; min-height: 40px; line-height: 2.4; padding: 0; color: #f0f0f0; font-weight: 600; font-size: 16px; border-bottom: 1px solid #092a3b; background: #233d4a; margin: 0;
}
a {
display:block;
}
a.active {
background-color:red;
}
<ul>
<li class="nav-item">
<a class="" data-toggle="collapse" href="#" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">1</a>
<div id="collapseOne" class="collapse" data-parent="#Menu">
<ul class="nav nav-tabs" role="tablist">
<li class="nav-item" data-parent="#collapseOne">
<a class="" data-toggle="tab" href="#One1">1.1</a>
</li>
<li class="nav-item" data-parent="#collapseOne">
<a class="" data-toggle="tab" href="#One2">1.2</a>
</li>
<li class="nav-item" data-parent="#collapseOne">
<a class="" data-toggle="tab" href="#One3">1.3</a>
</li>
</ul>
</div>
</li>
<li class="nav-item">
<a class="" data-toggle="collapse" href="#" data-target="#collapseTwo" aria-expanded="true" aria-controls="collapseTwo">2</a>
<div id="collapseTwo" class="collapse" data-parent="#Menu">
<ul class="nav nav-tabs" role="tablist">
<li class="nav-item">
<a class="" data-toggle="tab" href="#Two1">2.1</a>
</li>
<li class="nav-item">
<a class="" data-toggle="tab" href="#Two2">2.2</a>
</li>
<li class="nav-item">
<a class="" data-toggle="tab" href="#Two3">2.3</a>
</li>
</ul>
</div>
</li>
<li class="nav-item">
<a class="" data-toggle="tab" href="#Three">3</a>
</li>
<li class="nav-item">
<a class="" data-toggle="tab" href="#Four">4</a>
</li>
</ul>
I am struggling to achieve a multi level tablist menu with collapsible sub menus with Bootstrap 4. I need to use tabs and collapse at the same time. I have achieved to make the functionality (the right panes appearing and disappearing clicking the right links) work properly but there are more than one tab with the active class at the same time. I would like to know if there´s a way to make it work properly just with bootstrap 4 classes not adding more js/jquery code.
Here´s my codepen:
https://codepen.io/AlbertoAguado/pen/XqdmbK
The problem is combining tabs and collapse on the same parent level. Currently, 1&2 toggle tabs, and 3&4 toggle collapse. You need to make them all collapse with tabs inside (exactly like collapse 1&2), or make them all collapse items inside the #Menu.
Additionally, you need to hide any shown tabs when one of the collapse elements is hidden..
$('.collapse').on('hide.bs.collapse', function () {
$('.tab-content .show').removeClass('show');
})
https://codeply.com/go/Aq4zWAcUkX

Arrange nav tabs to single row in css/html

Im want to arrange all the nav tabs in a single row (in line with hr element).
I dont want any space between hr element and tabs.
After updating margin-top, for Technical Documentation tab, it seems fine, but for 1st tab , Products tab, still gap seems to be there between the hr.
Gap in the 1st tab
I have the below code like:
UPDATED:
<div class="container">
<ul class="nav nav-tabs search-results-navtab">
<li class="active search-list-class">
<a data-toggle="tab" href="#products">Products <br/></a>
</li>
<li class="search-list-class">
<a data-toggle="tab" href="#multilayer_inductors_series"> Technical
<br/>Documentation</a>
</li>
<li class="search-list-class">
<a data-toggle="tab" href="#smdpower_inductors_series">Support</a>
</li>
<li class="search-list-class">
<a data-toggle="tab" href="#molding_inductors_series">Component
<br/> Selector</a>
</li>
<li class="search-list-class">
<a data-toggle="tab" href="#shieldedsmdpower_inductors_series">Quality</a>
</li>
</ul>
<hr class="search-hr">
</div>
The Css is as:
.search-hr {
margin-top: 0px;
}
.search-results-navtab {
padding-left: 0px;
margin-left: 32px;
margin-right: 70px;
margin-bottom: 1px;
list-style: none;
border: 0px !important;
background-color: white;
}
.search-list-class {
padding-right: 100px;
}
Solution #1
Remove the margin-top value from the hr element.
hr {
margin-top: 0px;
}
This will retain the margin-bottom value which you may need for spacing.
Solution #2
Alternatively, and I would recommend this, remove the hr element and declare border-bottom on a containing parent element of your list items (li), like .nav, then declare a margin-bottom property if you need bottom spacing.
<div class="container">
<ul class="nav nav-tabs search-results-navtab">
<li class="active search-list-class">
<a data-toggle="tab" href="#products">Products <br/></a>
</li>
<li class="search-list-class">
<a data-toggle="tab" href="#multilayer_inductors_series"> Technical
<br/>Documentation</a>
</li>
<li class="search-list-class">
<a data-toggle="tab" href="#smdpower_inductors_series">Support</a>
</li>
<li class="search-list-class">
<a data-toggle="tab" href="#molding_inductors_series">Component
<br/> Selector</a>
</li>
<li class="search-list-class">
<a data-toggle="tab" href="#shieldedsmdpower_inductors_series">Quality</a>
</li>
</ul>
</div>
Additional Styles Declared:
.nav {
border-bottom: 1px solid #ccc;
margin-bottom: 10px; /* adjust as per requirement */
}

Bootstrap navtab hover does not cover full tab

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.