My code is below. Notice the tab 'one' is active. But the problem is when i open the page, the tab really shows active, BUT the tab content does not show ; it only shows when i click on the tab manually. How to fix this ?
<ul class="nav nav-tabs">
<li class="nav active"><a data-toggle="tab" href="#one">One</a>
</li>
<li class="nav"><a data-toggle="tab" href="#two">Two</a>
</li>
</ul>
<div class="tab-content">
<div class="tab-pane fade in" id="one">
<p>Tab one content</p>
</div>
<div class="tab-pane fade in" id="two">
<p>Tab two content</p>
</div>
</div>
Answer: Use the HTML5 localStorage Object In Bootstrap, if you refresh the page the tab is reset to default setting. However, you can use the HTML5 localStorage object to save some parameter for the current tab locally in the browser and get it back to make the last active tab selected on page reload.
To make the tabs toggleable, add the data-toggle="tab" attribute to each link. Then add a . tab-pane class with a unique ID for every tab and wrap them inside a <div> element with class . tab-content .
With the help of HTML, CSS, and JavaScript, it is possible to create a navigation menu with a curved active tab. This can be done by using the ::before and ::after pseudo-elements to create the desired shape, and then using JavaScript to add the active class to the element.
<div class="tab-pane fade in" id="one"> <p>Tab one content</p> </div>
Change this to
<div class="tab-pane active in" id="one"> <p>Tab one content</p> </div>
Add class active
also on the selected tab content
<ul class="nav nav-tabs">
<li class="nav active"><a data-toggle="tab" href="#one">One</a></li>
<li class="nav"><a data-toggle="tab" href="#two">Two</a></li>
</ul>
<div class="tab-content">
<!-- Show this tab by adding `active` class -->
<div class="tab-pane fade in active" id="one">
<p>Tab one content</p>
</div>
<!-- I removed `in` class here so it will have a fade in effect when showed -->
<div class="tab-pane fade" id="two">
<p>Tab two content</p>
</div>
</div>
Have a look at this: Fiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With