The issue of Bootstrap dynamic tabs retaining their active state even after switching tabs, leading to elements being stacked

For my university project, I am developing a website that resembles a text editor using Bootstrap as the framework. To create the website menus, dynamic tabs have been utilized. The following is the code snippet I have implemented:

    <!--Bootstrap styling import-->
    <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="03616c6c77707771627343362d302d30">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
    <!--Creation of the dynamic tabs-->
    <ul class="nav nav-tabs" id="myTab" role="tablist">
        <li class="nav-item" role="presentation">
            <button class="nav-link px-4" id="file-tab" data-bs-toggle="tab" data-bs-target="#file-tab-pane" type="button" role="tab" aria-controls="file-tab-pane" aria-selected="false">File</button>
        </li>
        <li class="nav-item" role="presentation">
            <button class="nav-link active px-4" id="home-tab" data-bs-toggle="tab" data-bs-target="#home-tab-pane" type="button" role="tab" aria-controls="home-tab-pane" aria-selected="true">Home</button>
        </li>
        <li class="nav-item" role="presentation">
            <button class="nav-link px-4" id="edit-tab" data-bs-toggle="tab" data-bs-target="#edit-tab-pane" type="button" role="tab" aria-controls="edit-tab-pane" aria-selected="false">Edit</button>
        </li>
        <li class="nav-item" role="presentation">
            <button class="nav-link px-4" id="layout-tab" data-bs-toggle="tab" data-bs-target="#layout-tab-pane" type="button" role="tab" aria-controls="layout-tab-pane" aria-selected="false">Layout</button>
        </li>
    </ul>
    <div class="tab-content border border-1" id="myTabContent">
        <!--Content in the file tab-->
        <div class="tab-pane fade" id="file-tab-pane" role="tabpanel" aria-labelledby="file-tab" tabindex="0">...</div>
        <!--Content in the home tab-->
        <div class="tab-pane fade show active d-flex justify-content-center my-2" id="home-tab-pane" role="tabpanel" aria-labelledby="home-tab" tabindex="0">
          <div class="d-flex align-items-center overflow-auto gap-1">
            <button type="button" class="btn" id="boldButton" data-bs-toggle="button"><b>B</b></button>
            <button type="button" class="btn" id="italicsButton" data-bs-toggle="button"><i>I</i></button>
            <button type="button" class="btn" id="underlineButton" data-bs-toggle="button"><u>U</u></button>
            <select class="ms-5" name="font" id="font">
                <option value="times-new-roman">Times New Roman</option>
                <option value="helvetica">Helvetica</option>
                <option value="garamond">Garamond</option>
                <option value="calibri">Calibri</option>
                <option value="arial">Arial</option>
            </select>
            <button type="button" class="btn" id="increaseFontSize">Size△</button>
            <button type="button" class="btn me-5" id="decreaseFontSize">Size▽</button>
            <button type="button" class="btn" data-bs-toggle="button">Left Align</button>
            <button type="button" class="btn" data-bs-toggle="button">Centre Align</button>
            <button type="button" class="btn" data-bs-toggle="button">Right Align</button>
            <button type="button" class="btn" data-bs-toggle="button">Justify</button>
            <select name="spacing" id="spacing">
                <option value="" disabled selected>Line Spacing</option>
                <option value="0.5">0.5</option>
                <option value="1">1</option>
                <option value="1.5">1.5 (Default)</option>
                <option value="2">2</option>
                <option value="2.5">2.5</option>
            </select>
            <button type="button" class="btn ms-5">Bulleted List</button>
            <button type="button" class="btn">Numbered List</button>
          </div> 
        </div>
        <!--Content in the edit tab-->
        <div class="tab-pane fade d-flex justify-content-center my-2" id="edit-tab-pane" role="tabpanel" aria-labelledby="edit-tab" tabindex="0">
            <div class="d-flex align-items-center overflow-auto gap-1">
                <button type="button" class="btn">Undo</button>
            </div>
        </div>
        <!--Content in the layout tab-->
        <div class="tab-pane fade" id="layout-tab-pane" role="tabpanel" aria-labelledby="layout-tab" tabindex="0">...</div>
    </div>
    <div class="text-area d-flex justify-content-center my-5">
        <div id="input" contenteditable="true"></div>
    </div>
    <!--Bootstrap js import-->
    <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5b3934342f282f293a2b1b6e75687568">[email protected]</a>/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>

Upon inspecting the webpage, I noticed an issue where switching from the home to the edit tab results in buttons within the edit tab stacking below within the div. It seems like the buttons from the home tab are still present but invisible. Adding more buttons within another tab further compounds this issue, causing overlapping. Here is a visual representation of the problem:

https://i.stack.imgur.com/3IKda.png

I have attempted various solutions such as removing custom stylesheets and JS code, converting list elements to divs, changing button types to links within their respective div elements, but none have resolved the problem.

Answer №1

To enhance the tab panes, eliminate the utilization of the d-flex class. This class enforces the style display: flex !important, conflicting with the default display: none; applied to the panes through the .tab-content>.tab-pane rule. The addition of this class is redundant as it is already present on the singular child div container within the panes. Additionally, remember to transfer the justify-content property to the child.

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

Is there a way for me to determine if a domain has been registered by the client?

I'm interested in creating a Web app that allows users to enter a domain name and then uses JavaScript to check its availability. I'm wondering if there's a method to do this without relying on my own hosting server. Is it possible to send a ...

Retrieving information from an API and transferring it to the state in a React component

I am currently working on a random quote generator project, and I'm facing some difficulties in passing the API data to my state and also accessing it in the QuoteComponent through props. Despite following all the correct procedures, whenever I try to ...

The functionality of Angular Views is experiencing issues

I'm confused as to why the JavaScript isn't functioning properly. Whenever I click on the links, the views fail to load. <html ng-app> <head> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/a ...

updating the page using the latest AJAX function

I have a webpage that showcases the newest images. I am utilizing an AJAX request to organize these images : $('#trier').on('click', function() { // Clicking on the button triggers sorting action var b = document.getElementByI ...

How can I create a loop to iterate through form/input files with varying titles?

Looping through input files with different titles Hello, I am trying to figure out how to loop through an input file with different titles. Each input file has a unique title, such as Safety Data Sheet, Certificate, etc. This is my current code: $titles ...

What is the best way to obtain the post id when making a JavaScript Ajax request?

I am currently developing a website similar to Stack Overflow for practice purposes. I am currently working on implementing the voting system. My goal is to have an Ajax call triggered when the upvote or downvote button is clicked, sending parameters such ...

The status of "Checked" has now been set to untrue

As a beginner, I am struggling to understand how the value changes in my code. Here is a screenshot of the Material UI switch: In the provided code snippet, the value event.target.checked is coming from the following Switch component: <Switch c ...

Click event not triggering to update image

I'm currently working on a Codepen project where I want to use JavaScript to change the image of an element with the id "chrome". However, my code doesn't seem to be working as expected. Can someone help me troubleshoot and fix this issue? Your a ...

What is the method for utilizing HSL instead of RGB in the global declaration of SCSS using the JavaScript API

This is how my next.config.js file is structured: // next.config.js const env = require('./site.config').env; const Colour = require('sass').types.Color; const {r, g, b} = require('./site.config').customProperties; const wit ...

An easy guide to using validators to update the border color of form control names in Angular

I'm working on a form control and attempting to change the color when the field is invalid. I've experimented with various methods, but haven't had success so far. Here's what I've tried: <input formControlName="pe ...

What is the best way to handle a very large JSON output in Node.js?

Working with shell.js to run unix commands in node.js and using bull for task queuing. The process involves providing an array of tasks: { "tasks": [ { "name": "task1", "command" ...

An issue has occurred with NPM CI where the bindings are not available from watchpack-chokidar2:fsevents

After executing npm ci on GitHub Actions, I encountered the following error: Run npm ci npm ERR! bindings not accessible from watchpack-chokidar2:fsevents npm ERR! A complete log of this run can be found in: npm ERR! /home/runner/.npm/_logs/2021-09-17 ...

Capture audio using a web browser

Currently working on a project to create a platform for recording sounds. I'm aiming to incorporate a meter that measures the volume of the sound. Despite extensive research, I haven't been able to discover an HTML5 solution compatible with all b ...

Leveraging both Angular Material UI and Tailwind CSS simultaneously

Recently, I've been incorporating Material UI with Angular. With the deprecation of flexlayout and the rise of Tailwind as a recommended alternative, I'm wondering if it's feasible to utilize both Material UI and Tailwind in tandem. How can ...

When converting JavaScript to PHP using AJAX, PHP retrieves an empty array

I am attempting to send a file from JavaScript to PHP using AJAX, but PHP is receiving an empty array. Currently, I am working on creating a web page through which I can pass a file to PHP in order for it to access and save information from the file into ...

What is the best way to pass a state within a route component in react-router?

... import { useNavigate, NavigateFunction } from "react-router"; ... function Form(): JSX.Element { const navigateToCountry = (country: string) => { // Code to navigate to country page with the given country } const [selectedCount ...

Is there a way to disable certain CSS features in Chrome, like CSS grid, for testing purposes?

I'm exploring alternative layouts for my app in case CSS grid is not supported. Is there a way to disable features like CSS grid in Chrome or Canary? ...

Argument for setInterval function

As a newcomer to programming, I am attempting to develop a basic javascript game. I have encountered an issue with the window.setInterval function and it seems to be causing everything to malfunction. I have been following a tutorial at this link and att ...

Center-aligned Bootstrap responsive column with a fixed width

Currently, I am working on creating a login page with a fixed width and a centered column layout. This is similar to the design of the login page at https://www.amazon.com/sign-in. I attempted to achieve this layout using offset columns, as shown below: ...

Is the Typescript index signature limited to only working with the `any` type?

I recently made changes to my interface and class structure: export interface State { arr : any[]; } export const INITIAL_STATE: State = { arr: [] }; This updated code compiles without any issues. Now, I decided to modify the Interface to incl ...