Bootstrap 5 akordion menjadi terlalu lebar apabila dikembangkan
P粉163465905
P粉163465905 2023-09-08 12:34:40
0
1
580

Saya menjangkakan komponen akordion akan mengembang agar sepadan dengan lebar elemen induknya, tetapi apabila ia mengembang, ia bukan sahaja mengembang sendiri, tetapi juga elemen induk, menyebabkan anak tetingkap kiri menjadi mampat dengan banyak. Apakah yang perlu dilakukan untuk mencapai tingkah laku yang diingini? Saya akan menghargai sebarang jawapan.

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/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>

Saya cuba melaraskan sedikit lebar tajuk akordion dan kandungannya, tetapi itu tidak berjaya.

P粉163465905
P粉163465905

membalas semua(1)
P粉536909186

#right-pane 元素没有显式声明 flex-basiswidth,因此它将占用所需的空间。当手风琴关闭时,它会按照您的预期工作,因为它的内容宽度较窄(然后由于 flex-grow 中的 flex-grow: 1 ,然后会增长以填充剩余空间-1 kategori). Walau bagaimanapun, apabila kandungan akordion dipaparkan, kandungan tersebut akan cuba mengambil sebanyak mungkin ruang mendatar.

Untuk mengelakkan perkara ini, sila pertimbangkan #pane kanan元素上设置某种flex-basiswidth,例如width :25%通过w-25` di sini:

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/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>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan