Problems with Bootstrap's nav-tab menus - html

Just like in the Inception movie, I'm trying to make a main navbar menu with dynamic tabs that contains a second navbar menu that shows other content.
I started the first nav-tabs menu using the template found at the Bootstrap 5 documentation page and it's running fine but the second nav-tab menu complicates things when trying to make it be triggered by a tab on the first menu. This gif explains better what I'm trying to do.
This the code I've written so far:
<ul class="nav nav-tabs" id="myTab" role="tablist">
<li class="nav-item" role="presentation">
<button class="nav-link active" id="stat-tab" data-bs-toggle="tab" data-bs-target="#stat" type="button" role="tab" aria-controls="second-stat-tab" aria-selected="true">STAT</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="inv-tab" data-bs-toggle="tab" data-bs-target="#inv" type="button" role="tab" aria-controls="inv" aria-selected="false">INV</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="map-tab" data-bs-toggle="tab" data-bs-target="#map" type="button" role="tab" aria-controls="map" aria-selected="false">MAP</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="radio-tab" data-bs-toggle="tab" data-bs-target="#radio" type="button" role="tab" aria-controls="radio" aria-selected="false">RADIO</button>
</li>
</ul>
<!-- BEGINNING OF SECOND TABLIST -->
<div class="tab-content" id="myTabContent">
<ul class="nav nav-tabs" id="myTab" role="tablist">
<li class="nav-item">
<button class="nav-link" id="second-stat-tab" data-bs-toggle="tab" data-bs-target="#stat" type="button" role="tab" aria-controls="stat" aria-selected="true">STATUS</button>
</li><li class="nav-item">
<button class="nav-link" id="special-tab" data-bs-toggle="tab" data-bs-target="#special" type="button" role="tab" aria-controls="special">SPECIAL</button>
</li>
</ul>
</div>
<!-- END OF THE SECOND TABLIST -->
<!-- This is the content of the tabs-->
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="stat" role="tabpanel" aria-labelledby="second-stat-tab">This is the status tab sample content
<div class="center-image">
<img src="vault_boy-removebg-preview_CROPPED.png" alt="">
</div>
</div>
<div class="tab-pane fade" id="special" role="tabpanel" aria-labelledby="special-tab">SPECIAL</div>
<div class="tab-pane fade" id="perks" role="tabpanel" aria-labelledby="perks-tab">PERKS</div>
</div>
In this pen you can see the full code and the way the it behaves. I want the second nav-tab menu to show only as a result of clicking on the first tab of the first menu (the one called "STATS") but it just remains there.

Related

Why tabs are not changing nav nav-tabs?

I am using bootstrap for creating a tab list like below one:
The problem is that when I click on "Profile" or Contact, it changes nothing. I included the bootstrap library. I mean it doesn't remove the 'active', 'show' classes. Does someone know why?
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/js/bootstrap.bundle.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<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="#home" role="tab" aria-controls="home" aria-selected="true">Home</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">Profile</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">Contact</a>
</li>
</ul>
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">...</div>
<div class="tab-pane fade" id="profile" role="tabpanel" aria-labelledby="profile-tab">...</div>
<div class="tab-pane fade" id="contact" role="tabpanel" aria-labelledby="contact-tab">...</div>
</div>
Somewhat unsure which approach you're after. This can work out of the box with Bootstrap 5 but you also tag this with Bootstrap 4.
For version 5 they changed:
data-toggle
to
data-bs-toggle
Here is the approach with no additions and uses Bootstrap 5. Note your code example brings in jQuery and that isn't needed.
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<!-- Nav tabs -->
<ul class="nav nav-tabs" id="myTab" role="tablist">
<li class="nav-item">
<a class="nav-link active" data-bs-toggle="tab" aria-controls="home" aria-selected="true" href="#home">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" data-bs-toggle="tab" href="#menu1">Profile</a>
</li>
<li class="nav-item">
<a class="nav-link" data-bs-toggle="tab" href="#menu2">Contact</a>
</li>
</ul>
<!-- Tab panes -->
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="home" role="tabpanel" aria-controls="home">
Home
</div>
<div class="tab-pane fade" id="menu1" role="tabpanel" aria-controls="profile">
Profile
</div>
<div class="tab-pane fade" id="menu2" role="tabpanel" aria-controls="contact">
Contact
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous">
</script>
Used below script and worked smoothly
$('#myTab a').on('click', function (e) {
e.preventDefault()
$(this).tab('show')
})

Laravel 6 nav tabs cannot navigate into tab only shown in url (myweb/pages#tab1)

i can't navigate into tabs pages only it show in URL (myweb/pages#tab1 .. myweb/pages/#tab2 ..)
please help me
enter image description here
<div class="card-body">
<ul class="nav nav-tabs" id="myTab" role="tablist">
<li class="nav-item">
<a class="nav-link " id="home-tab" data-toggle="tab" href="#page1" role="tab" aria-controls="page1"
aria-selected="true">page one</a>
</li>
<li class="nav-item">
<a class="nav-link" id="profile-tab" data-toggle="tab" href="#page2" role="tab" aria-controls="page2"
aria-selected="false">page two</a>
</li>
<li class="nav-item">
<a class="nav-link" id="contact-tab" data-toggle="tab" href="#page3" role="tab" aria-controls="page3"
aria-selected="false">page three</a>
</li>
</ul>
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="page1" role="tabpanel">
page one
</div>
<div class="tab-pane fade" id="page2" role="tabpanel" >
page two
</div>
<div class="tab-pane fade" id="page3" role="tabpanel">
page three
</div>
</div>
</div>
</div>
Try this :
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
Bootstrap from that link work perfect for my and i try this on your problem and i can navigate

Bootstrap 4 nav pills in navbar

I am new to bootstrap and want to have nav pills in my navigation bar to switch the content of the page (like tabs). Without the navbar it is working, but i would like to have it in my navbar.
This is my code so far:
<nav class="navbar navbar-dark bg-dark navbar-expand-sm">
<span class="navbar-brand mb-0 h1">ioBroker</span>
<ul class="navbar-nav nav-pills">
<li class="nav-item active">
<a class="nav-link active" id="tab-1" data-toggle="tab" role="tab" href="#content-1" aria-selected="true" aria-controls="content-1">Content 1</a>
</li>
<li class="nav-item">
<a class="nav-link" id="tab-2" data-toggle="tab" role="tab" href="#content-2" aria-selected="false" aria-controls="content-2">Content 2</a>
</li>
</ul>
</nav>
<main role="main" class="container-full">
<div class="container-full">
<div class="tab-content">
<div class="tab-pane fade show active" id="content-1" aria-labelledby="tab-1" role="tabpanel">Content 1</div>
<div class="tab-pane fade" id="content-2" aria-labelledby="tab-2" role="tabpanel">Content 2</div>
</div>
</div>
</main>
The issue i have, is that i can't switch back to an already opened "tab". I fi remove the "data-toggle" property, it works for the buttons, but not for the content switching.
Add the nav class to the nav-pills, and the content switching will work as expected for Tabs...
<ul class="navbar-nav nav nav-pills">
<li class="nav-item active">
<a class="nav-link active" id="tab-1" data-toggle="tab" role="tab" href="#content-1" aria-selected="true" aria-controls="content-1">Content 1</a>
</li>
<li class="nav-item">
<a class="nav-link" id="tab-2" data-toggle="tab" role="tab" href="#content-2" aria-selected="false" aria-controls="content-2">Content 2</a>
</li>
</ul>
Demo: https://www.codeply.com/go/Xr6tLFbqKj

Bootstrap Tabbed Nav/Split Dropdown Button Issue

I tried adding a tabbed nav to a page, like this:
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#home">Home</a></li>
<li><a data-toggle="tab" href="#menu1">Menu 1</a></li>
<li><a data-toggle="tab" href="#menu2">Menu 2</a></li>
</ul>
<div class="tab-content">
<div id="home" class="tab-pane fade in active">
<h3>HOME</h3>
<p>Some content.</p>
</div>
<div id="menu1" class="tab-pane fade">
<h3>Menu 1</h3>
<p>Some content in menu 1.</p>
</div>
<div id="menu2" class="tab-pane fade">
<h3>Menu 2</h3>
<p>Some content in menu 2.</p>
</div>
</div>
But it was being displayed incorrectly:
So I switch from Bootstrap 4.0.0 to 3.3.7, and it appears properly, but my split dropdown menu button breaks.
<li class="nav-item">
<div class="btn-group">
<button type="button" class="btn btn-primary">{{ session.username }}</button>
<button type="button" class="btn btn-primary dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="sr-only">Toggle Dropdown</span>
</button>
<div class="dropdown-menu dropdown-menu-right">
<a class="dropdown-item" href="/get_messages">Messages</a>
<a class="dropdown-item" href="/get_friend_requests">Friend Requests</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="/logout">Log Out</a>
</div>
</div>
</li>
How can I have both components display correctly? Switching between 4.0.0 and 3.3.7 breaks one or the other.
Nav-tabs work differently in bootstrap version 4, you need:
<ul class="nav nav-tabs">
<li class="nav-item">
<a class="nav-link active" data-toggle="tab" href="#home">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#menu1">Menu 1</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#menu2">Menu 2</a>
</li>
</ul>
Note sure about this, but bootstrap 4 documentation uses show class for the active tab-content (you may need to replace in with show):
<div id="home" class="tab-pane fade show active">
See here: W3Schools Bootstrap 4 nav-tabs
See here: Bootstrap 4 documentation

Navbar contents not changing

Below is my code. For some reason when I load the page the navbar shows the contents of "Home". When I click on the Menu tab every works properly. But for some reason when I click on the Scheme tab I only get the Home tab contents
<div class="container">
<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="#home" role="tab" aria-controls="home" aria-selected="true">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" id="menu-tab" data-toggle="tab" href="#menu" role="tab" aria-controls="menu" aria-selected="false">Menu</a>
</li>
<li class="nav-item">
<a class="nav-link" id="scheme-tab" data-toggle="tab" href="#scheme" role="tab" aria-controls="scheme" aria-selected="false">Scheme</a>
</li>
</ul>
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">home tab</div>
<div class="tab-pane fade" id="menu" role="tabpanel" aria-labelledby="menu-tab">
<div class="input-group mb-3">
<ul>
<div class="input-group-prepend">
<button class="btn btn-outline-secondary" id="addItem" type="button">Add Item to Menu</button>
</div>
<input type="text" class="form-control" id="addItemInput" placeholder="Enter New Item Here" aria-label="" aria-describedby="basic-addon1">
<ul id="dynamic-list"></ul>
</ul>
</div>
</div>
<div class="tab-pane fade" id="scheme" role="tabpanel" aria-labelledby="scheme-tab">What?</div>
</div>
</div>
I feel like it must be something really simple, thanks in advance.
Your code looks fine to me, and should work. I suspect there is an issue with how you are loading your jQuery and Bootstrap JS and CSS files. Check the console to see if there are any errors.
Here is a working sample of your code - where I am simply using the latest jQuery & Bootstrap CDN files:
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
<div class="container">
<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="#home" role="tab" aria-controls="home" aria-selected="true">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" id="menu-tab" data-toggle="tab" href="#menu" role="tab" aria-controls="menu" aria-selected="false">Menu</a>
</li>
<li class="nav-item">
<a class="nav-link" id="scheme-tab" data-toggle="tab" href="#scheme" role="tab" aria-controls="scheme" aria-selected="false">Scheme</a>
</li>
</ul>
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">home tab</div>
<div class="tab-pane fade" id="menu" role="tabpanel" aria-labelledby="menu-tab">
<div class="input-group mb-3">
<ul>
<div class="input-group-prepend">
<button class="btn btn-outline-secondary" id="addItem" type="button">Add Item to Menu</button>
</div>
<input type="text" class="form-control" id="addItemInput" placeholder="Enter New Item Here" aria-label="" aria-describedby="basic-addon1">
<ul id="dynamic-list"></ul>
</ul>
</div>
</div>
<div class="tab-pane fade" id="scheme" role="tabpanel" aria-labelledby="scheme-tab">What?</div>
</div>
</div>