Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap tab - active class not working on page loading

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>
like image 713
delphirules Avatar asked Aug 18 '15 17:08

delphirules


People also ask

How to keep the current tab active on page reload in Bootstrap?

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.

How do I change the active tab in bootstrap?

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 .

How to make current tab active in HTML?

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.


2 Answers

<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> 
like image 128
jafaritaqi Avatar answered Sep 20 '22 21:09

jafaritaqi


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

like image 44
Robin Carlo Catacutan Avatar answered Sep 21 '22 21:09

Robin Carlo Catacutan