I'm using basic Bootstrap 5.3 with the basic pills and tab structure. How can I simply add a fadeOut to the active tab before the fadeIn of the selected tab?
It seems like adding the "fade" class only adds a fadeIn, I want the active tab to slowly disappear before.
The only way I have found so far is to override the whole mechanism and do a jQuery fadeout fadein. I wish I could use more standard code...
Can some please help?
Thanks!
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
<ul class="nav nav-pills mb-3" id="pills-tab" role="tablist">
<li class="nav-item" role="presentation">
<button class="nav-link active" id="pills-home-tab" data-bs-toggle="pill" data-bs-target="#pills-home" type="button" role="tab" aria-controls="pills-home" aria-selected="true">Home</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="pills-profile-tab" data-bs-toggle="pill" data-bs-target="#pills-profile" type="button" role="tab" aria-controls="pills-profile" aria-selected="false">Profile</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="pills-contact-tab" data-bs-toggle="pill" data-bs-target="#pills-contact" type="button" role="tab" aria-controls="pills-contact" aria-selected="false">Contact</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="pills-disabled-tab" data-bs-toggle="pill" data-bs-target="#pills-disabled" type="button" role="tab" aria-controls="pills-disabled" aria-selected="false" disabled>Disabled</button>
</li>
</ul>
<div class="tab-content" id="pills-tabContent">
<div class="tab-pane fade show active" id="pills-home" role="tabpanel" aria-labelledby="pills-home-tab" tabindex="0">...</div>
<div class="tab-pane fade" id="pills-profile" role="tabpanel" aria-labelledby="pills-profile-tab" tabindex="0">...</div>
<div class="tab-pane fade" id="pills-contact" role="tabpanel" aria-labelledby="pills-contact-tab" tabindex="0">...</div>
<div class="tab-pane fade" id="pills-disabled" role="tabpanel" aria-labelledby="pills-disabled-tab" tabindex="0">...</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7jL+jjXkk+Q2h455rYXK/7HAuoJl+0I4" crossorigin="anonymous"></script>
You could do it like this. The notes are below the example.
The example itself was posted like this (instead of breaking it into appropriate parts in the snippet editor) because there were issues in getting it to work as it does now. I suspect it has something to do with the way the external files are loaded on SO.
Some caveats / YMMV / general notes:
data-bs-targetinside the pills / menu buttons, has been emptied, to prevent default Bootstrap behaviour. This might lead to some problems later on, if you rely on the behaviour which no longer works as it once did by default.tab-paneitems has been set toabsolute, to achieve the overlapping. Again, this might not work for you and your specific use-case, especially if you have additional content below your tabs (footers, sliders, blocks of text, etc). In that case, you would have to place your tabbed content inside a container, and perhaps define a fixed height (with overflow and optional changes for different resolutions).fade:not(.show)and.tab-content > .tab-panein the initial Bootstrap setup), this solution / suggestion applies changes in opacity