Using Bootstrap 5, I am able to display tab content that always displays (no matter which tab the user is in):
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
<!-- Tabs navs -->
<ul class="nav nav-tabs" id="tabNavs01">
<li class="nav-item"><a id="t-customer" data-bs-toggle="tab" class="nav-link active" href="#tabcustomer">customer</a></li>
<li class="nav-item"><a id="t-position" data-bs-toggle="tab" class="nav-link" href="#tabposition">position</a></li>
</ul>
<!-- Tabs content -->
<div class="tab-content col-md-7 flex-nowrap" id="tabCont01">
<div class="tab-pane fade show active" id="tabcustomer">
<div class="input-group flex-nowrap">
<h2>ENTER: </h2>
<input type="text" value="" name="" id="txtcustomer" placeholder="customer" class="form-control add-main" onclick="validatecustomer();">
<input type="text" value="" name="" id="txtcomputer" placeholder="computer" class="form-control add-computer" onclick="validatecustomer();">
</div>
</div>
<div class="tab-pane fade" id="tabposition">
<div class="input-group flex-nowrap">
<h2>ENTER: </h2>
<input type="text" value="" name="" id="txtposition" placeholder="position" class="form-control position-box" onclick="searchByposition();">
</div>
</div>
<div>
<label><strong>Testing</strong></label>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
This produces the area “Testing” that appears in both tabs as desired:
My question is how can I get this “Testing” text to appear to the right of both tabs? I am trying to get it to this location inside the “white” area and aligned with the words “ENTER” as seen here:
Update
Thank you Kameron, your solution below worked nice. If I wanted to add some svg in this area, would that be possible such as this Facebook/Twitter images:
3
Answers
To display tab content that always shows regardless of which tab the user is currently in using Bootstrap 5, you can add the "show active" classes to the content element of the first tab. This will ensure that the content is visible by default and will not be hidden when switching between tabs.
I added two changes to achieve that based on your structure
d-flex
class to.tab-content
.tab-pane { flex-grow: 1; }
Have a look on the snippet result.
To get "Testing" next to the
tab-content
you have to use.d-flex
on the.tab-pane
parent. You already had.flex-nowrap
, but it is invalid without having.d-flex
or anotherflex
class.Next, you can just use Bootstraps
.flex-grow-1
class on the first and second child to.tab-content
.You can then configure out your
widths
etc, but as long as you haved-flex
on the parent with.flex-nowrap
you will always have your desired "Testing" div next to each.tab-pane
.