Expanding the Bootstrap 5 accordion causes it to extend beyond the designated width

My initial expectation was for the accordion component to expand to match its parent's width. However, upon expansion, it not only enlarges itself but also causes the parent element to compress significantly. What steps should be taken to achieve the desired behavior? Any insights or solutions would be greatly appreciated.

<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d0b2bfbfa4a3a4a2b1a090e5fee3fee0">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="12707d7d66616660736252273c213c22">[email protected]</a>/dist/js/bootstrap.bundle.min.js" integrity="sha384-geWF76RCwLtnZ8qwWowPQNguL3RmwHVBC9FhGdlKrxdiJJigb/j/68SIy3Te4Bkz" crossorigin="anonymous"></script>

<div id="container" class="d-flex flex-column align-items-stretch w-100 h-100">
      <div class="d-flex align-items-stretch h-100" style="min-height:0">
        <div id="left-pane" class="border border-secondary rounded-1 w-25 m-3 me-2 p-2 bg-light overflow-y-auto">
          <div class="list-group">
            <a href="" class="list-group-item active">An active item</a>
          </div>
        </div>
        <div id="right-pane" class="flex-grow-1 d-flex flex-column border border-secondary rounded-1 m-3 ms-2 p-2 bg-light overflow-y-auto">
          <ul class="nav nav-tabs h-auto" id="tabs" role="tablist">
            <li class="nav-item" role="presentation">
              <button 
                class="nav-link active" 
                id="tab1" 
                data-bs-toggle="tab" 
                data-bs-target="#tab1-pane" 
                type="button" 
                role="tab" 
                aria-controls="tab1-pane" 
                aria-selected="true">
                  System info
              </button>
            </li>
            <li class="nav-item" role="presentation">
              <button 
                class="nav-link" 
                id="tab2" 
                data-bs-toggle="tab" 
                data-bs-target="#tab2-pane" 
                type="button" 
                role="tab" 
                aria-controls="tab2-pane" 
                aria-selected="false">
                  Profile
              </button>
            </li>
          </ul>
          <div class="tab-content h-100 w-100 overflow-y-auto px-3 py-2 border-start border-bottom border-end rounded-bottom" id="tabs-content">
            <div 
              class="tab-pane fade show active" 
              id="tab1-pane" 
              role="tabpanel" 
              aria-labelledby="tab1" 
              tabindex="0">
                <div class="accordion" id="accordionPanelsStayOpenExample">
                  <div class="accordion-item">
                    <h2 class="accordion-header">
                      <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#panelsStayOpen-collapseOne" aria-expanded="false" aria-controls="panelsStayOpen-collapseOne">
                        Accordion Item #1
                      </button>
                    </h2>
                    <div id="panelsStayOpen-collapseOne" class="accordion-collapse collapse">
                      <div class="accordion-body w-auto h-auto">
                        <strong>This is the first item's accordion body.</strong> It is shown by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow.
                      </div>
                    </div>
                  </div>
                </div>
            </div>
            <div 
              class="tab-pane fade" 
              id="tab2-pane" 
              role="tabpanel" 
              aria-labelledby="tab2" 
              tabindex="0">
                tab2 content  
            </div>
          </div>
        </div>
      </div>
    </div>

Attempts were made to adjust the accordion header and its content width slightly, but no successful outcome was achieved.

Answer â„–1

When the accordion's content is revealed, the #right-pane element expands to fill the horizontal space available because no flex-basis or width has been explicitly declared for it. This expansion can lead to the content occupying more space than desired.

To prevent this issue, consider specifying a flex-basis or width for the #right-pane element, such as setting a width of 25% using the w-25 class:

<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0f6d60607b7c7b7b7572027075306772692f2128">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a6c4c9c9d2d5d2d4c7d6e69388958896">[email protected]</a>/dist/js/bootstrap.bundle.min.js" integrity="sha384-geWF76RCwLtnZ8qwWowPQNguL3RmwHVBC9FhGdlKrxdiJJigb/j/68SIy3Te4Bkz" crossorigin="anonymous"></script>

<div id="container" class="d-flex flex-column align-items-stretch w-100 h-100">
      <div class="d-flex align-items-stretch h-100" style="min-height:0">
        <div id="left-pane" class="border border-secondary rounded-1 w-25 m-3 me-2 p-2 bg-light overflow-y-auto">
          <div class="list-group">
            <a href="" class="list-group-item active">An active item</a>
          </div>
        </div>
        <div id="right-pane" class="flex-grow-1 d-flex flex-column border border-secondary rounded-1 m-3 ms-2 p-2 bg-light overflow-y-auto w-25">
          <ul class="nav nav-tabs h-auto" id="tabs" role="tablist">
            <li class="nav-item" role="presentation">
              <button 
                class="nav-link active" 
                id="tab1" 
                data-bs-toggle="tab" 
                data-bs-target="#tab1-pane" 
                type="button" 
                role="tab" 
                aria-controls="tab1-pane" 
                aria-selected="true">
                  System info
              </button>
            </li>
            <li class="nav-item" role="presentation">
              <button 
                class="nav-link" 
                id="tab2" 
                data-bs-toggle="tab" 
                data-bs-target="#tab2-pane" 
                type="button" 
                role="tab" 
                aria-controls="tab2-pane" 
                aria-selected="false">
                  Profile
              </button>
            </li>
          </ul>
          <div class="tab-content h-100 w-100 overflow-y-auto px-3 py-2 border-start border-bottom border-end rounded-bottom" id="tabs-content">
            <div 
              class="tab-pane fade show active" 
              id="tab1-pane" 
              role="tabpanel" 
              aria-labelledby="tab1" 
              tabindex="0">
                <div class="accordion" id="accordionPanelsStayOpenExample">
                  <div class="accordion-item">
                    <h2 class="accordion-header">
                      <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#panelsStayOpen-collapseOne" aria-expanded="false" aria-controls="panelsStayOpen-collapseOne">
                        Accordion Item #1
                      </button>
                    </h2>
                    <div id="panelsStayOpen-collapseOne" class="accordion-collapse collapse">
                      <div class="accordion-body w-auto h-auto">
                        <strong>This is the first item's accordion body.</strong> It is shown by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow.
                      </div>
                    </div>
                  </div>
                </div>
            </div>
            <div 
              class="tab-pane fade" 
              id="tab2-pane" 
              role="tabpanel" 
              aria-labelledby="tab2" 
              tabindex="0">
                tab2 content
            </div>
          </div>
        </div>
      </div>
    </div>

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

<ul><li>issue with indentation

Is there a way to eliminate the indent from my unordered list? While inspecting the element, I noticed what appears to be padding between the width of the box and the content. However, setting padding to 0px and margin to 0px doesn't seem to work as t ...

Show several popovers concurrently by hovering over text utilizing Bootstrap 3's popover feature

Is there a way to display multiple popovers at once when hovering over text, similar to the example provided in this link? I attempted the following method, but it wasn't successful. <div class="row"> <div class="col-md-12"><br/&g ...

Can CSS3 animations be executed sequentially for each child element?

Have you ever tried creating a CSS3 animation in HTML? You can check out an example here. <div class="parent"> <a href="#">First</a> <a href="#">Second</a> <a href="#">Third</a> </div> With the ...

Steps for aligning items in a column horizontally in Bootstrap 5

After creating a Grid system with only 2 columns, I placed text in the first column and a carousel in the second. Despite setting a custom size for the carousel image, I'm facing difficulty centering it horizontally within the column. .title-sec { ...

Utilizing and incorporating distinct html elements on a separate webpage

I am in the process of developing a dynamic newspaper-style website where articles will be regularly updated and replaced on the Home Page. Each article featured on the Home Page will serve as a link to a separate page for full details. These article links ...

Is the Bootstrap success icon displaying in white on white instead of the traditional green color?

I recently sourced code directly from the Bootstrap documentation (see below), but I'm encountering an issue where my "success" badge appears as white text on a white background. The text is there, as I can highlight it, but it's not displaying c ...

Extracting data from websites and importing it into Excel with VBA

I am venturing into the world of web scraping for the first time using VBA. My goal is to extract pricing information from our company's distributors and save it in an Excel file for our sales team to analyze. The process involves taking the URL from ...

Changing CSS classes with each click of the user, using Jquery

Looking for a way to seamlessly switch between two links with different CSS classes each time a user clicks? Here's what's currently happening: <a class="class1" id="class1">Class1</a> <a class="class2" id="class2">Class2</a ...

Generate a collection of div elements as child nodes

I'm working on a project where I have multiple rows with input fields. My goal is to create an array for each row that contains the values of the inputs. For example, if I have 3 rows and the values of 'input1' are 1, 'input2' are ...

What is the best way to adjust the animation settings for SweetAlert2's Toast feature?

I recently integrated SweetAlert2's toast notifications into my web application and customized the animation using the customClass parameter to have the notification slide in from the right side. However, there are a couple of things I'm struggli ...

What is the process for choosing a table column by clicking on the "select" option?

Welcome to my project! Here is an example table that I'm working on. I have a question - how can I make it so that when I click on "choose me", the entire column is selected? Can you help me with this? <table> <tr> <th>plan A&l ...

Tips for arranging three images in a single row

I have 3 payment logos in my footer that I want to center and align in one row. Can someone help me with this? sliki { text-align: justify; } sliki img { display: inline-block; width: 75px; height: 100px; padding: 7px; margin-top: -5px; ...

Creating a Scroll Window That Influences the Scroll Div Content

How can I sync scrolling in Windows with the scrolling of a div content, such as on WordPress editor pages? Let's say I have the following elements: Header Article Footer The div content has the following style: .my-div {    overflow-y: auto;  ...

Having trouble with a React child component not reacting to a click event?

The current issue I am experiencing is that the component is not triggering a click event when the button is clicked. TickerPage render() { return ( <div className="TickerPage"> <div className="TickerPage-container"> <b ...

Generate a scrollable element and adjust its dimensions to fit the window

Currently, my webpage features a header at the top followed by a sidebar on the left and the main content area on the right. I am looking for a solution that will allow the main content area to scroll independently from the side bar. --------------------- ...

Easy fix for 3 circles (images) placed in a row with equal distance between them and perfectly aligned

I've been spending the last 3 days trying to accomplish this specific task: 3 circular images arranged horizontally with equal spacing Occupying 70% of the central screen area Height and width based on percentages for browser resizing adjustment It ...

HTML5 sortable lists, ajax posting, and inactive elements are not functioning correctly

I'm currently utilizing a fantastic plugin for jQuery known as HTML5 Sortable. It can be found at . I am attempting to disable certain items using this plugin. My approach involves adding the class="disabled" to the <li> tag and including items ...

Positioning divs around a circle can be quite challenging

Among my collection of divs with various classes and multiple child divs representing guests at a table, each main div symbolizes a specific restaurant table type. I have created a jsfiddle for demonstration. http://jsfiddle.net/rkqBD/ In the provided ex ...

The CSS file is causing the footer to be cut off from the page and

My webpage is not scrolling properly when I add a lot of content, causing the footer to get cut off. I have tried various solutions found in other questions, but none have worked for me. Can anyone offer any suggestions or advice to fix this issue? html ...

Styling and structuring your website with CSS and HTML

I am coding an HTML page where I've incorporated CSS for the styling. However, I'm facing an issue with the drop-down menu. Whenever I try to click on a drop-down option, it disappears. How can I fix this? I want the drop-down options to be clic ...