On initial page load, the tabs show but the content for that selected tab does not.
If I click the "Link" tab and back to the "Post" tab then it shows up.
<div class="container">
<div class="card text-center">
<div class="card-header">
<ul class="nav nav-tabs card-header-tabs" id="tabs">
<li class="nav-item">
<a class="active nav-link" href="#post" data-toggle="tab">Post</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#link" data-toggle="tab">Link</a>
</li>
</ul>
</div>
<div class="card-body">
<div class="tab-content">
<div class="tab-pane" id="post">post</div>
<div class="tab-pane" id="link">link</div>
</div>
</div>
</div>
</div>
On page load it looks like this (the div with the tab-pane class hasn't been displayed):
There are no errors in my console and the bootstrap JS file is loaded. There are some similar questions around but the solutions have not worked for me.
What do I need to add to get the tab pane to display when the page loads?
Check this out
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="card text-center">
<div class="card-header">
<ul class="nav nav-tabs card-header-tabs" id="tabs">
<li class="nav-item">
<a class="active nav-link active" href="#post" data-toggle="tab">Post</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#link" data-toggle="tab">Link</a>
</li>
</ul>
</div>
<div class="card-body">
<div class="tab-content">
<div class="tab-pane active" id="post">post</div>
<div class="tab-pane" id="link">link</div>
</div>
</div>
</div>
</div>
The root cause of your problem was the fade class. Well done ! Removing it is the solution.
Related
I have a main jsp and within this jsp in the other jsp divs that are displayed according to the selected menu
when I enter the index jsp it loads all the jsp at the beginning, but when I enter data in the a.jsp and select the b.jsp (which has new information loaded in the a.jsp) it does not reload the jsp
how can I do it??
I do not know if I explained well
index.jsp
<div class="container">
<nav class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<ul class="nav navbar-nav">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
Mantenedores <b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li class="active"><a href="#a" role="tab" data-toggle="tab" >A</a></li>
<li>B</li>
<li><a href="#c" role="tab" data-toggle="tab" >C</a></li>
</ul>
</li>
</ul>
</div>
<div class="tab-content active">
<div role="tabpanel" class="tab-pane" id="a">
<jsp:include page="a.jsp"/>
</div>
<div role="tabpanel" class="tab-pane" id="b">
<jsp:include page="b.jsp"/>
</div>
<div role="tabpanel" class="tab-pane" id="c">
<jsp:include page="c.jsp"/>
</div>
</div>
</div>
I have created toggleable tabs using Bootstrap 4 "tablist", they are toggleable and work great.
I want to create an "All" tab that will show all of the content of all the different tabs and can't figure out how to make an "All" tab work!
Any help is greatly appreciated!
Here are my tab headings:
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<div>
<ul class="nav nav-tabs nav-justified" role="tablist">
<li class="nav-item"><a class="nav-link active" data-toggle="tab" href="#cases">Cases</a></li>
<li class="nav-item"><a class="nav-link" data-toggle="tab" href="#revrul">Rev. Rul.s & Notices</a></li>
<li class="nav-item"><a class="nav-link" data-toggle="tab" href="#regs">Regulations</a></li>
</ul>
<div class="tab-content">
<div id="cases" class="container tab-pane active"><br>
<h3>Cases</h3>
<ul> Content for cases here</ul>
</div>
<div id="revrul" class="container tab-pane fade"><br>
<h3>Rev. Rul.s & Notices</h3>
<ul> Content for rulings here</ul>
</div>
</div>
<div id="regs" class="container tab-pane fade"><br>
<h3>Regulations</h3>
<ul> Content for regulations here </ul>
</div>
</div>
You would have to manually add some JS that controls the behavior of the "All" link.
What you want to do is:
Create a special tab for showing all content, with ID #show_all
When you click this tab, it adds classes .active and .show to all the panes, so that they'll all be visible.
When you click on a tab that does not have the #show_all ID, it removes the classes .show and .active from all the tab panes that are not the one that you're looking for.
Here's a working snippet.
$("#show_all").on("click", function() {
$(this).addClass("active").parent("li").siblings().find("a").removeClass("active");
$(".tab-pane").removeClass("fade").addClass("active").addClass("show");
});
$(".nav-link").not("#show_all").on("click", function() {
console.log(this.hash);
$(".tab-pane").not(this.hash).removeClass("active").removeClass("show");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" />
<ul class="nav nav-tabs nav-justified" role="tablist">
<li class="nav-item"><a class="nav-link active" data-toggle="tab" href="#cases">Cases</a></li>
<li class="nav-item"><a class="nav-link" data-toggle="tab" href="#revrul">Rev. Rul.s & Notices</a></li>
<li class="nav-item"><a class="nav-link" data-toggle="tab" href="#regs">Regulations</a></li>
<li class="nav-item"><a class="nav-link" href="#" id="show_all">All</a></li>
</ul>
<div class="tab-content">
<div id="cases" class="container tab-pane active"><br>
<h3>Cases</h3>
<ul> Content for cases here</ul>
</div>
<div id="revrul" class="container tab-pane fade"><br>
<h3>Rev. Rul.s & Notices</h3>
<ul> Content for rulings here</ul>
</div>
<div id="regs" class="container tab-pane fade"><br>
<h3>Regulations</h3>
<ul> Content for regulations here </ul>
</div>
</div>
Try this
$( ".tabContent" ).clone().appendTo("#tabContent");
<script src="http://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="http://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<link href="http://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>
<ul class="nav nav-tabs nav-justified" role="tablist">
<li class="nav-item"><a class="nav-link active" data-toggle="tab" href="#all">All</a></li>
<li class="nav-item"><a class="nav-link" data-toggle="tab" href="#cases">Cases</a></li>
<li class="nav-item"><a class="nav-link" data-toggle="tab" href="#revrul">Rev. Rul.s & Notices</a></li>
<li class="nav-item"><a class="nav-link" data-toggle="tab" href="#regs">Regulations</a></li>
</ul>
<div class="tab-content">
<div id="all" class="container tab-pane active">
<h3>ALL</h3>
<div id="tabContent">
</div>
</div>
<div id="cases" class="container tab-pane active">
<div class="tabContent">
<h3>Cases</h3>
<ul> Content for cases here</ul>
</div>
</div>
<div id="revrul" class="container tab-pane fade">
<div class="tabContent">
<h3>Rev. Rul.s & Notices</h3>
<ul> Content for rulings here</ul>
</div>
</div>
<div id="regs" class="container tab-pane fade">
<div class="tabContent">
<h3>Regulations</h3>
<ul> Content for regulations here </ul>
</div>
</div>
</div>
I have some tabs using bootstrap 4. In the tab with id "mytabs" I have other two tabs inside it. And in this tabs inside "#mytabs" that is an issue. If I click in the "tab1" link it appears the content of the tab1 but if I click in the "tab2" link it still appears the content of the "tab1".
Do you know where is the issue?
Fiddle with issue: https://jsfiddle.net/cv25swga/8/
HTML:
<body>
<div class="bg-light-gray2">
<div class="container nopadding py-4">
<div class="row mt-3">
<div class="col-12">
<ul class="nav nav-pills bg-light-gray registration_form_list" role="tablist">
<!-- other tab links -->
<li class="disabled">
<a class="nav-link" href="#mytabs" data-toggle="tab" role="tab">
<i class="fa fa-lock" aria-hidden="true"></i>
<span class="d-none d-lg-inline-block">Access Data</span>
</a>
</li>
</ul>
<div class="tab-content registration_body bg-white" id="myTabContent">
<div class="tab-pane clearfix fade" id="mytabs" role="tabpanel"
aria-labelledby="contact-tab">
<div class="d-flex mb-3">
<ul class="nav nav-pills">
<li class="nav-item">
<a class="nav-link active border" id="tab1" href="#tab1"
data-toggle="tab"
role="tab">tab1</a>
</li>
<li class="nav-item">
<a class="nav-link border" id="tab2" href="#tab2"
data-toggle="tab" role="tab">tab2</a>
</li>
</ul>
</div>
<div class="tab-content bg-white" id="myTabContent">
<div class="tab-pane fade show active clearfix" id="tab1" role="tabpanel"
aria-labelledby="home-tab">
tab1
</div>
<div class="tab-pane fade show clearfix" id="tab2" role="tabpanel"
aria-labelledby="home-tab">
tab2
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
This is caused by the fact both your tabs and the links have the same ID.
Change your IDs up so that they are unique on the page and the problem will disappear.
I have an google maps in a tab with bootstrap, but the map become to small, so i want to change a bootstrap grid system when i click on fa icon, i want the first column torns to col-md-8, and the second column torn to col-md-4.
thx,
here my code:
<h2 class="block-title">Mapas Brasil</h1>
<div class="row">
<div class="col-md-6">
<ul class="nav nav-tabs nav-cptec">
<li class="nav-item">
<a class="nav-link active" data-toggle="tab" href="#menu1" role="tab">Condição Atual</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#menu2" role="tab">Aviso</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#menu3" role="tab">Temperaturas</a>
</li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="menu1" role="tabpanel">
<div id="map-canvas"></div>
</div>
<div class="tab-pane" id="menu2" role="tabpanel">Aviso</div>
<div class="tab-pane" id="menu3" role="tabpanel">Temperaturas</div>
</div>
<div class="col-md-6">
<ul class="nav nav-tabs nav-justified nav-cptec">
<li class="nav-item">
<a class="d-flex align-items-center nav-link active" data-toggle="tab" href="#menu-1" role="tab">Anánalise Sinótica</a>
</li>
<li class="nav-item">
<a class="d-flex align-items-center nav-link" data-toggle="tab" href="#menu-2" role="tab">Imagens de Satélite</a>
</li>
<li class="nav-item">
<a class="d-flex align-items-center nav-link" data-toggle="tab" href="#menu-3" role="tab">Vale do Paraíba</a>
</li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="menu-1" role="tabpanel">
<img src="/images/sinotica.png" alt="" class="img-fluid">
</div>
<div class="tab-pane" id="menu-2" role="tabpanel">Satélite</div>
<div class="tab-pane" id="menu-3" role="tabpanel">Vale</div>
</div>
<img src="http://i.imgur.com/mE72FHG.png" alt="Faça sua analise sinótica" class="img-fluid top5" width="100%">
</div>
</div>
$('#abrir').click(function() {
$('#teste').removeClass('col-md-6').addClass('col-md-8 open');
$('#teste2').removeClass('col-md-6').addClass('col-md-4');
});
$('body').click(function(e){
//Detect if click is outside #abrir AND is "open"
if($(e.currentTarget).closest('#abrir').length==0 && $('#abrir').hasClass('open')){
$('#teste').addClass('col-md-6').removeClass('col-md-8 open');
$('#teste2').addClass('col-md-6').removeClass('col-md-4');
}
});
This should do the trick. What you want is to reverse what you do on the click element. Put an event on the body, to listen for every click and inside this handler, see if the clicked element is inside or outside the targeted element to make sure we trigger accordingly.
You'll have to make sure that all click handlers on your page do not prevent event bubbling (it shouldn't, as it is bad practice) or else the click outside the element will not always be seen...
i added this code and change the column to col-md-6 to col-md-4, but when i click out, dont turn back.
javascript its the same that you gave to me
my code:
<div class="row">
<div id="teste" class="col-md-6">
<ul class="nav nav-tabs nav-cptec">
<li class="nav-item">
<a class="nav-link active" data-toggle="tab" href="#menu1" role="tab">Condição Atual</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#menu2" role="tab">Aviso</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#menu3" role="tab">Temperaturas</a>
</li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="menu1" role="tabpanel">
<i class="fa fa-arrow-circle-o-right" aria-hidden="true" id="abrir"></i>
<div id="map-canvas"></div>
</div>
<div class="tab-pane" id="menu2" role="tabpanel">Aviso</div>
<div class="tab-pane" id="menu3" role="tabpanel">Temperaturas</div>
</div>
</div>
<div class="container">
<br>
<ul class="nav nav-pills">
<li class=" active btn-primary "><a data-toggle="pill" href="#home">Ask</a></li>
<li class=" btn-primary "><a data-toggle="pill" href="#menu1">Reviews</a></li>
<li class=" btn-info " ><a data-toggle="pill" href="#menu3">WRITE A REVIEW</a></li>
<li class=" btn-info "><a data-toggle="pill" href="#menu2">ASK A QUESTION</a></li>
</ul>
<br>
<div class="tab-content">
<div id="home" class="tab-pane fade in active">
some content tab 1
</div>
<div id="menu1" class="tab-pane fade">
some content tab 2
</div>
<div id="menu2" class="tab-pane fade">
some content tab 3
</div>
<div id="menu3" class="tab-pane fade">
some content tab 4
</div>
</div>
</div>
It takes double clicks on a tab to change the active tab from one to another.... the tab content changes on one click but the active tab is shown as home tab and changes only on second click on same tab.
P.S. I am using angular
try to use data-target instead of href as when you use href your url also changes.. and the url of your current page changes..