Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap 4 navigation tabs content not showing content on initial page load

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):

enter image description here

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?

like image 563
Chris Avatar asked Sep 30 '18 23:09

Chris


Video Answer


2 Answers

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>
like image 52
Sakib Anjum Avatar answered Oct 11 '22 17:10

Sakib Anjum


The root cause of your problem was the fade class. Well done ! Removing it is the solution.

like image 3
Abdelrahman ELGAMAL Avatar answered Oct 11 '22 17:10

Abdelrahman ELGAMAL