【问题标题】:Using Bootstrap's nav-tabs causes child div to overflow使用 Bootstrap nav-tabs 导致子 div 溢出
【发布时间】:2018-05-06 18:40:46
【问题描述】:

我有一个大小正确的 div,我想在其中放置标签和一些子 div。内部 div 将是可滚动的。当标签不存在时,这正常工作。

当我添加 Bootstrap 导航选项卡时,它们会向下“推”子 div 并且它会溢出选项卡的高度。我该如何定义“这个 div 应该占用父级 剩余 空间的 100%?

<div class="fill" id="div-camera-details"> <!--This div is correctly sized, it has max-height set to 100%-->
    <ul class="nav nav-tabs nav-justified" data-tabs="tabs">
        <li class="nav-item" id="overview-tab-button"><a class="nav-link" data-toggle="tab"
                                                         href="#overview-tab">Přehled</a></li>
        <li class="nav-item" id="gallery-tab-button"><a class="nav-link active" data-toggle="tab"
                                                        href="#gallery-tab">Galerie</a></li>
    </ul>
    <div class="container-fluid fill highlight-border-solid">
        <div class="tab-content fill">
            <div role="tabpanel" class="tab-pane" id="overview-tab">
                <div>Some content</div>
            </div>
            <div role="tabpanel" class="tab-pane in active fill" id="gallery-tab">
                <div class="container y-scrollable">
                    <div>Some looong content</div>
                </div>
            </div>
        </div>
    </div>
</div>

This is a simple depiction of what I have. 在底部可以看到溢出。浅灰色边框是内容应该结束的地方。实心边框(用于调试)是由 highlight-border-solid 类引起的,可以看出,该 div 溢出。

感谢您的帮助

【问题讨论】:

    标签: html css twitter-bootstrap


    【解决方案1】:

    我通过像这样减去像素高度来解决这个问题:

    .tab-body {
        height: calc(100% - 41px);
    }
    

    使用 HTML:

    <div class="fill" id="div-camera-details"> <!--This div is correctly sized, it has max-height set to 100%-->
        <ul class="nav nav-tabs nav-justified" data-tabs="tabs">
            <li class="nav-item" id="overview-tab-button"><a class="nav-link" data-toggle="tab"
                                                             href="#overview-tab">Přehled</a></li>
            <li class="nav-item" id="gallery-tab-button"><a class="nav-link active" data-toggle="tab"
                                                            href="#gallery-tab">Galerie</a></li>
        </ul>
        <div class="container-fluid tab-content tab-body">
                <div role="tabpanel" class="tab-pane" id="overview-tab">
                    <div>Some content</div>
                </div>
                <div role="tabpanel" class="tab-pane in active fill" id="gallery-tab">
                    <div class="container y-scrollable">
                        <div>Some looong content</div>
                    </div>
                </div>
        </div>
    </div>
    

    这对我来说似乎并不“干净”,但现在它必须这样做。

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题,但使用的是 bootstrap 4.1 flexbox 实用程序。请参阅下面的示例代码,看看它是否可以帮助您获得“更清洁”的解决方案。

      就我而言,我正在寻找一种解决方案,以便在不同的屏幕尺寸下正确显示选项卡的内容。

      <!DOCTYPE html>
      <html lang="en">
      <head>
        <title>Bootstrap Example no nested</title>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script>
        <style>
          html, body {
            height: 100%;
          }
      
          .overflow-auto {
            overflow: auto;
          }
      
          .card-main {
            overflow: hidden;
          }
      
          .max-height-0 { /* resolve problema de não exibir a barra de rolagem quando necessário no Firefox, Edge e IE */
            max-height: 0;
          }
        </style>
      </head>
      <body>
      
        <div class="container-fluid h-100">
          <div class="card card-main h-100">
            <h5 class="card-header text-center bg-primary text-white">Agenda</h5>
            <div class="card-body d-flex flex-column h-100">
      
      
              <div class="form-group row xxxflex-shrink-0 h-100">
                <div class="col-2 d-flex flex-column h-100"></div>
                <div class="col-8 d-flex flex-column h-100 bg-danger">
      
      
      
                  <div class="form-group row flex-shrink-0">
                    <div class="col-8"><input type="text" class="form-control" /></div>
                    <div class="col-4"><button type="button" class="btn btn-primary btn-block">Pesquisar</button></div>
                  </div>
                  <div class="form-group row xd-flex xflex-grow-1 xflex-fill h-100">
                    <div class="col-12 d-flex flex-column">
      
      
                      <ul class="nav nav-tabs" id="myTab" role="tablist">
                        <li class="nav-item">
                          <a class="nav-link active" id="home-tab" data-toggle="tab" href="#home" role="tab" aria-controls="home" aria-selected="true">Home</a>
                        </li>
                        <li class="nav-item">
                          <a class="nav-link" id="profile-tab" data-toggle="tab" href="#profile" role="tab" aria-controls="profile" aria-selected="false">Profile</a>
                        </li>
                        <li class="nav-item">
                          <a class="nav-link" id="contact-tab" data-toggle="tab" href="#contact" role="tab" aria-controls="contact" aria-selected="false">Contact</a>
                        </li>
                      </ul>
                      <div class="tab-content h-100" id="myTabContent">
                        <div class="tab-pane fade show active h-100" id="home" role="tabpanel" aria-labelledby="home-tab">
                          <div class="card h-100 bg-primary">
                            <div class="card-body d-flex flex-column h-100 overflow-auto">
                              <div class="max-height-0">
                                <p>1Raw denim you probably haven't heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache cliche tempor, williamsburg carles vegan helvetica. Reprehenderit butcher retro keffiyeh dreamcatcher synth. Cosby sweater eu banh mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum iphone. Seitan aliquip quis cardigan american apparel, butcher voluptate nisi qui.</p>
                                <p>2Raw denim you probably haven't heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache cliche tempor, williamsburg carles vegan helvetica. Reprehenderit butcher retro keffiyeh dreamcatcher synth. Cosby sweater eu banh mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum iphone. Seitan aliquip quis cardigan american apparel, butcher voluptate nisi qui.</p>
                                <p>3Raw denim you probably haven't heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache cliche tempor, williamsburg carles vegan helvetica. Reprehenderit butcher retro keffiyeh dreamcatcher synth. Cosby sweater eu banh mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum iphone. Seitan aliquip quis cardigan american apparel, butcher voluptate nisi qui.</p>
                                <p>4Raw denim you probably haven't heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache cliche tempor, williamsburg carles vegan helvetica. Reprehenderit butcher retro keffiyeh dreamcatcher synth. Cosby sweater eu banh mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum iphone. Seitan aliquip quis cardigan american apparel, butcher voluptate nisi qui.</p>
                                <p>5Raw denim you probably haven't heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache cliche tempor, williamsburg carles vegan helvetica. Reprehenderit butcher retro keffiyeh dreamcatcher synth. Cosby sweater eu banh mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum iphone. Seitan aliquip quis cardigan american apparel, butcher voluptate nisi qui.</p>
                                <p>6Raw denim you probably haven't heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache cliche tempor, williamsburg carles vegan helvetica. Reprehenderit butcher retro keffiyeh dreamcatcher synth. Cosby sweater eu banh mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum iphone. Seitan aliquip quis cardigan american apparel, butcher voluptate nisi qui.</p>
                                <p>7Raw denim you probably haven't heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache cliche tempor, williamsburg carles vegan helvetica. Reprehenderit butcher retro keffiyeh dreamcatcher synth. Cosby sweater eu banh mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum iphone. Seitan aliquip quis cardigan american apparel, butcher voluptate nisi qui.</p>
                                <p>8Raw denim you probably haven't heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache cliche tempor, williamsburg carles vegan helvetica. Reprehenderit butcher retro keffiyeh dreamcatcher synth. Cosby sweater eu banh mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum iphone. Seitan aliquip quis cardigan american apparel, butcher voluptate nisi qui.</p>
                                <p>9Raw denim you probably haven't heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache cliche tempor, williamsburg carles vegan helvetica. Reprehenderit butcher retro keffiyeh dreamcatcher synth. Cosby sweater eu banh mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum iphone. Seitan aliquip quis cardigan american apparel, butcher voluptate nisi qui.</p>
                                <p>10Raw denim you probably haven't heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache cliche tempor, williamsburg carles vegan helvetica. Reprehenderit butcher retro keffiyeh dreamcatcher synth. Cosby sweater eu banh mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum iphone. Seitan aliquip quis cardigan american apparel, butcher voluptate nisi qui.</p>
                                <p>11Raw denim you probably haven't heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache cliche tempor, williamsburg carles vegan helvetica. Reprehenderit butcher retro keffiyeh dreamcatcher synth. Cosby sweater eu banh mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum iphone. Seitan aliquip quis cardigan american apparel, butcher voluptate nisi qui.</p>
                                <p>12Raw denim you probably haven't heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache cliche tempor, williamsburg carles vegan helvetica. Reprehenderit butcher retro keffiyeh dreamcatcher synth. Cosby sweater eu banh mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum iphone. Seitan aliquip quis cardigan american apparel, butcher voluptate nisi qui.</p>
                                <p>13Raw denim you probably haven't heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache cliche tempor, williamsburg carles vegan helvetica. Reprehenderit butcher retro keffiyeh dreamcatcher synth. Cosby sweater eu banh mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum iphone. Seitan aliquip quis cardigan american apparel, butcher voluptate nisi qui.</p>
                                <p>14Raw denim you probably haven't heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache cliche tempor, williamsburg carles vegan helvetica. Reprehenderit butcher retro keffiyeh dreamcatcher synth. Cosby sweater eu banh mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum iphone. Seitan aliquip quis cardigan american apparel, butcher voluptate nisi qui.</p>
                                <p>15Raw denim you probably haven't heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache cliche tempor, williamsburg carles vegan helvetica. Reprehenderit butcher retro keffiyeh dreamcatcher synth. Cosby sweater eu banh mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum iphone. Seitan aliquip quis cardigan american apparel, butcher voluptate nisi qui.</p>
                                <p>16Raw denim you probably haven't heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache cliche tempor, williamsburg carles vegan helvetica. Reprehenderit butcher retro keffiyeh dreamcatcher synth. Cosby sweater eu banh mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum iphone. Seitan aliquip quis cardigan american apparel, butcher voluptate nisi qui.</p>
                                <p>17Raw denim you probably haven't heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache cliche tempor, williamsburg carles vegan helvetica. Reprehenderit butcher retro keffiyeh dreamcatcher synth. Cosby sweater eu banh mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum iphone. Seitan aliquip quis cardigan american apparel, butcher voluptate nisi qui.</p>
                                <p>18Raw denim you probably haven't heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache cliche tempor, williamsburg carles vegan helvetica. Reprehenderit butcher retro keffiyeh dreamcatcher synth. Cosby sweater eu banh mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum iphone. Seitan aliquip quis cardigan american apparel, butcher voluptate nisi qui.</p>
                                <p>19Raw denim you probably haven't heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache cliche tempor, williamsburg carles vegan helvetica. Reprehenderit butcher retro keffiyeh dreamcatcher synth. Cosby sweater eu banh mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum iphone. Seitan aliquip quis cardigan american apparel, butcher voluptate nisi qui.</p>
                              </div>
                            </div>
                          </div>
                        </div>
                        <div class="tab-pane fade h-100" id="profile" role="tabpanel" aria-labelledby="profile-tab">
                          <div class="card h-100">
                            <div class="card-body d-flex flex-column h-100 overflow-auto">
                              <div class="max-height-0">
                                <p>Food truck fixie locavore, accusamus mcsweeney's marfa nulla single-origin coffee squid. Exercitation +1 labore velit, blog sartorial PBR leggings next level wes anderson artisan four loko farm-to-table craft beer twee. Qui photo booth letterpress, commodo enim craft beer mlkshk aliquip jean shorts ullamco ad vinyl cillum PBR. Homo nostrud organic, assumenda labore aesthetic magna delectus mollit. Keytar helvetica VHS salvia yr, vero magna velit sapiente labore stumptown. Vegan fanny pack odio cillum wes anderson 8-bit, sustainable jean shorts beard ut DIY ethical culpa terry richardson biodiesel. Art party scenester stumptown, tumblr butcher vero sint qui sapiente accusamus tattooed echo park.</p>
                              </div>
                            </div>
                          </div>
                        </div>
                        <div class="tab-pane fade h-100" id="contact" role="tabpanel" aria-labelledby="contact-tab">
                          <div class="card h-100">
                            <div class="card-body d-flex flex-column h-100 overflow-auto">
                              <div class="max-height-0">
                                <p>Etsy mixtape wayfarers, ethical wes anderson tofu before they sold out mcsweeney's organic lomo retro fanny pack lo-fi farm-to-table readymade. Messenger bag gentrify pitchfork tattooed craft beer, iphone skateboard locavore carles etsy salvia banksy hoodie helvetica. DIY synth PBR banksy irony. Leggings gentrify squid 8-bit cred pitchfork. Williamsburg banh mi whatever gluten-free, carles pitchfork biodiesel fixie etsy retro mlkshk vice blog. Scenester cred you probably haven't heard of them, vinyl craft beer blog stumptown. Pitchfork sustainable tofu synth chambray yr.</p>
                              </div>
                            </div>
                          </div>
                        </div>
                      </div>
      
      
      
      
      
                    </div>
                  </div>
                </div>
                <div class="col-2 d-flex flex-column h-100 bg-primary"></div>
      
              </div>
            </div>
          </div>
        </div>
      
      </body>
      </html>
      

      【讨论】:

        猜你喜欢
        • 2015-11-14
        • 1970-01-01
        • 2014-01-06
        • 1970-01-01
        • 2014-08-05
        • 1970-01-01
        • 2015-12-14
        • 2021-01-01
        • 1970-01-01
        相关资源
        最近更新 更多