When vertical tabs are activated, they shift the page upwards

I recently utilized Bootstrap to create vertical tabs for my website.

My goal was to display additional text below the tab title only when that specific tab is active.

While I managed to achieve this, I encountered an issue where transitioning from one tab to another causes the page content to shift upwards.

Is there a way to resolve this issue without disrupting the layout of the page?

Example : https://jsfiddle.net/hm7n5bv4/

 .filler {
                background: cyan;
                height: 600px;
    }

    .nav-pills .nav-link .tab_subtitle_hide {
                font-size: 16px !important;
                visibility: hidden;
                height: 0;
                opacity: 0;
                transition: opacity 0.3s ease;
    }           
    .nav-pills .nav-link.active .tab_subtitle_hide {
                color: #fff;
                visibility: visible;
                height: auto;
                opacity: 1;
                transition: opacity 0.3s ease;
    }
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"
integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">

<div class="filler">Hello world</div>
</div>

<div class="row">
    <div class="col-3 nav flex-column nav-pills" id="v-pills-tab" role="tablist" aria-orientation="vertical">
        <a class="nav-link active" id="v-pills-for-teams-tab" data-toggle="pill" href="#v-pills-for-teams"
            role="tab" aria-controls="v-pills-for-teams" aria-selected="false"><i
                class="tab_i fad fa-users-class"></i>
            <div class="tab_content">For Teams
            </div>
            <div class="tab_subtitle_hide">Similar to a hierarchical organization, Dummy text allows you to
                structure
                users.</div>
        </a>

        <a class="nav-link" id="v-pills-for-small-business-tab" data-toggle="pill"
            href="#v-pills-for-small-business" role="tab" aria-controls="v-pills-for-small-business"
            aria-selected="false"><i class="tab_i fad fa-store"></i>
            <div class="tab_content">For small business

            </div>
            <div class="tab_subtitle_hide">Similar to a hierarchical organization, Dummy text allows you to
                structure
                users.</div>
        </a>

        <a class="nav-link" id="v-pills-for-enterprise-tab" data-toggle="pill" href="#v-pills-for-enterprise"
            role="tab" aria-controls="v-pills-for-enterprise" aria-selected="true">
            <div class="tab_content"><i class="tab_i fad fa-building"></i><span class="multi-company">For
                    enterprise</span><br></div>
            <div class="tab_subtitle_hide">Similar to a hierarchical organization, Dummy text allows you to
                structure
                users.</div>
        </a>
    </div>

    <div class="col-9 tab-content" id="v-pills-tabContent">
        <div class="tab-pane active show" id="v-pills-for-teams" role="tabpanel"
            aria-labelledby="v-pills-for-teams-tab">
            <!--Start sub-tab1-->..0
            <!--End sub-tab1-->
        </div>

        <div class="tab-pane" id="v-pills-for-small-business" role="tabpanel"
            aria-labelledby="v-pills-for-small-business-tab">
            <!--Start sub-tab2-->..1
            <!--End sub-tab2-->
        </div>


        <div class="tab-pane" id="v-pills-for-enterprise" role="tabpanel"
            aria-labelledby="v-pills-for-enterprise-tab">
            <!--Start sub-tab3-->..2
            <!--End sub-tab3-->
        </div>

    </div>

</div>

Answer №1

To ensure proper display of the content, it is necessary to set the max-height for the Wrapper element containing the content, in this case, the .nav-link.

For a practical example, refer to this link - https://jsfiddle.net/fLbuaxm8/

body{
  padding-bottom:20px;
}
.nav-link.active{
   max-height:500px;
  margin-bottom:0px;
}
.nav-link{
  max-height:0px;
  margin-bottom:50px;
}
.filler {
  background: cyan;
  height: 600px;
}

.nav-pills .nav-link .tab_subtitle_hide {
  font-size: 16px !important;
  visibility: hidden;
  max-height: 0;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.nav-pills .nav-link.active .tab_subtitle_hide {
  color: #fff;
  visibility: visible;
  max-height: 600px;
  opacity: 1;
  transition: opacity 0.3s ease;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"
    integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">

<div class="filler">Hello world</div>

<div class="row">
    <div class="col-3 nav flex-column nav-pills" id="v-pills-tab" role="tablist" aria-orientation="vertical">
        <a class="nav-link active" id="v-pills-for-teams-tab" data-toggle="pill" href="#v-pills-for-teams" role="tab"
            aria-controls="v-pills-for-teams" aria-selected="false"><i class="tab_i fad fa-users-class"></i>
            <div class="tab_content">For Teams
                <!--<br><div class="tab_subtitle_hide">Similar to a hierarchical organization, Dummy text allows you to structure users.</div>-->
            </div>
            <div class="tab_subtitle_hide">Similar to a hierarchical organization, Dummy text allows you to structure
                users.</div>
        </a>

        <a class="nav-link" id="v-pills-for-small-business-tab" data-toggle="pill" href="#v-pills-for-small-business"
            role="tab" aria-controls="v-pills-for-small-business" aria-selected="false"><i
                class="tab_i fad fa-store"></i>
            <div class="tab_content">For small business
                <!--<br><div class="tab_subtitle_hide">Similar to a hierarchical organization, Dummy text allows you to structure users.</div>-->
            </div>
            <div class="tab_subtitle_hide">Similar to a hierarchical organization, Dummy text allows you to structure
                users.</div>
        </a>

        <a class="nav-link" id="v-pills-for-enterprise-tab" data-toggle="pill" href="#v-pills-for-enterprise"
            role="tab" aria-controls="v-pills-for-enterprise" aria-selected="true" style="
    /* padding: 0 !important; */
">
            <div class="tab_content"><i class="tab_i fad fa-building"></i><span class="multi-company">For enterprise</span><br></div>
            <div class="tab_subtitle_hide">Similar to a hierarchical organization, Dummy text allows you to structure
                users.</div>
        </a>
    </div>

    <div class="col-9 tab-content" id="v-pills-tabContent">
        <div class="tab-pane active show" id="v-pills-for-teams" role="tabpanel" aria-labelledby="v-pills-for-teams-tab">
            <!--Inicio sub-tab1-->..0
            <!--Fim sub-tab1-->
        </div>

        <div class="tab-pane" id="v-pills-for-small-business" role="tabpanel"
            aria-labelledby="v-pills-for-small-business-tab">
            <!--Inicio sub-tab2-->..1
            <!--Fim sub-tab2-->
        </div>


        <div class="tab-pane" id="v-pills-for-enterprise" role="tabpanel"
            aria-labelledby="v-pills-for-enterprise-tab">
            <!--Inicio sub-tab3-->..2
            <!--Fim sub-tab3-->
        </div>

    </div>

</div>


<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"
    integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj"
    crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper/dist/umd/popper.min.js"
    integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN"
    crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"
    integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV"
    crossorigin="anonymous"></script>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for displaying a message in the model body when a bootstrap model does not have any data in jQuery

Having trouble displaying a text message in the Bootstrap modal body when there is no data available in the model. I have multiple cards in the model, and if I click on the skip or done buttons, each card will close. However, if there is only one card in t ...

Adjusting the size of a division element to match the dimensions

Currently, I am still in the process of finalizing the remainder of the page, but I have encountered a minor issue. The problem lies in my image div not matching the height of the container. Although the image itself is the correct size, the image div appe ...

The footer and login form are tangled up in a web of confusion

Here is my HTML code for a login form: <div class="middle-box text-center loginscreen"> <div> <form class="" role="form" action="index.html"> <div class="form-group&q ...

Using EJS Tags within an external CSS file

I have been working on refactoring a Node.js project, and I currently have my CSS code within my .ejs file. I need to incorporate some dynamic data into my CSS file. It works fine when the CSS is within the EJS file. However, when I move my CSS to an exte ...

Is it possible to embed a section of code from a different file?

Looking for a solution to streamline the process of updating multiple web pages with identical header and footer content. Currently have 5-10 pages with the same information, making it time-consuming to manually update each one when changes are needed. I ...

Is it possible to install just one component instead of the entire package?

NEWBIE IN REACT: Greetings! As I embark on my journey into the world of React development, I find myself working on a web application using Material UI. My current task involves implementing error and success messages, and I've set my sights on utili ...

An excellent foundation for an HTML document

I've been feeling the itch to dive back into web development and create some websites again. However, it's been a while since I've worked with HTML. I'm wondering if this skeleton for a website is a good starting point. If not, what cha ...

Move your cursor over the top and bottom of the image to experience distinct effects

Trying to create an effect where the top 50% of an image shows a different color and text when hovered over, and same for the bottom 50%. Currently, only able to achieve this effect for the lower half of the image. Is there a way to make it work for both h ...

Guide to Incorporating a Marker into an SVG Blinking Rectangular or Circular Border Image on Google Maps

I have a link that points to a specific location on Google Maps using latitude and longitude: http://www.google.com/intl/en_us/mapfiles/ms/micons/red-dot.png Now, I am looking to add a blinking border to this marker link. Is there a way to achieve this ...

Adjust the transparency of an image preview using jQuery

Currently, I am working on creating a video gallery for a friend and I am experimenting with changing the thumbnail opacity using jQuery fade effect. While I can achieve this with CSS, I want to implement it with jQuery for a smoother transition. If you ...

Spacing vertically within a table cell

I'm currently experimenting with creating a vertical text-align: justify effect between divs. I am working with a structure that includes 4 div elements inside a td, like this: <td> <div></div> <div></div> <div ...

Place a fresh banner on top of the Ionicon icon

I recently started using Ionicons from and I am not too familiar with css. My question is, can a banner that says 'new' be overlaid on the top right corner of the Icon? Is there a simple or standard method to achieve this? (whether it's an ...

Creating a stationary div element solely with Javascript, excluding the use of CSS, jQuery, and HTML

I've been searching all day for a solution to this issue without any success. I apologize if I overlooked any relevant posts on the topic. Currently, I am working with Qualtrics and attempting to implement a textbox with scrolling instructions that fo ...

Is it possible to achieve a seamless interaction by employing two buttons that trigger onclick events to alternately

I have a specific goal in mind: I want to create two buttons (left and right) with interactive cursors. The left button should initially have a cursor of "not-allowed" on hover, indicating that it cannot be clicked at the beginning. When the right button ...

Choose the initial p tag that includes an image, based on the content of another div

I am trying to figure out how to manipulate the code on my website: <div class="the-post-thumbnail"> <img src="" alt="" width="" height="" /> </div> <div class="post-body"> <p><img src="" alt="" width="" height="" ...

I am looking to adjust the height of my MUI Grid component

Recently exploring React, and I'm looking to set a height limit for MUI Grid. I've structured my project into 3 sections using MUI grid components. My goal is to restrict the page height in order to eliminate the browser scrollbar. If the conten ...

Creating dynamic animations with Keyframes in CSS

Query If we consider the illustration below: A-------------B------------C How can I begin an animation from the middle point (B), then have it move to A, return to B, and finally reach C? I attempted to create an example, but it is not functioning corre ...

How can I address the issue of an inner content scroll bar?

I am facing an issue with the scroll bar on inner content. When I hover over an arrow on the inner content, the scroll bar appears as desired. However, it changes the content in a way that looks odd. Is there a solution to have a scroll bar on the inner co ...

Obtain the URL found within the href tags

Is there a way to extract the links from the href tags? When I coded it, the entire 'a' tag is showing up... Here's the code: page = urllib2.urlopen('https://www.meetup.com/') soup = BeautifulSoup(page, 'lxml') categor ...

Issues with locating the fonts: React-slick paired with nextjs

Incorporating react-slick into a NextJs project has been quite seamless, however, I'm encountering issues with importing the necessary fonts from the CSS files. To address this snag, I've attempted the following steps: npm install slick-carouse ...