使用Bootstrap的nav-tabs会导致子div溢出

时间:2017-11-22 22:09:27

标签: html css twitter-bootstrap

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

当我添加Bootstrap nav-tabs时,他们会推送"孩子向下划分,它溢出了标签的高度。我如何定义"这个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溢出。

感谢您的帮助

2 个答案:

答案 0 :(得分:0)

我通过减去这样的像素高度来解决它:

.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>

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

答案 1 :(得分:0)

我遇到了同样的问题,但是使用了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>