柱子不占全高

Column doesnt take the full hight

我有一个问题:

正如您在图片中看到的那样,问题是该列没有占据全部高度。左边是我得到的,右边是我想要的。也许你们可以帮助我。这是导致左侧图像的源代码。我已经搜索了一个解决方案,但不幸的是没有适合我的源代码的东西。

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <title>Bootstrap Example</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.5.2/css/bootstrap.min.css">
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
    </head>
    <body>
    <div>
          <div class="row m-auto">
            <div class="col-md-12 p-0">
                <div>
                <nav class="navbar navbar-expand-lg navbar-light bg-light">
                    <a class="navbar-brand" href="#">
                        Navbar w/ text
              </a>
                    <button
                        class="navbar-toggler"
                        type="button"
                        data-toggle="collapse"
                        data-target="#navbarText"
                        aria-controls="navbarText"
                        aria-expanded="false"
                        aria-label="Toggle navigation"
                    >
                        <span class="navbar-toggler-icon"></span>
                    </button>
                    <div class="collapse navbar-collapse" id="navbarText">
                        <ul class="navbar-nav mr-auto">
                            <li class="nav-item active">
                                <a class="nav-link" href="#">
                                    Home <span class="sr-only">(current)</span>
                                </a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link" href="#">
                                    Features
                    </a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link" href="#">
                                    Pricing
                    </a>
                            </li>
                        </ul>
                        <span class="navbar-text">Navbar text with an inline element</span>
                    </div>
                </nav>
            </div>
              <div class="container-fluid">
                <div class="row">


                  <div class="col-md-4 bg-warning">
<!-- this is the left side -->
                            <div>
                      <div class="row m-1">
                        <div class="col-md-11">
                          Chats
                      </div>
                        <div class="col-md-1">
                          <i class="fas fa-plus-circle"></i>
                        </div>
                      </div>
                      <div class="row mb-2">
                        <div class="col-md-12">
                          <form class="form-inline" style={{ height: "0%", width: "100%", paddingLeft: "0", paddingRight: "0", paddingTop: "8px" }}>
                            <input class="form-control  mr-sm-1" style={{ width: "80%" }} type="search" placeholder="Suchen" aria-label="Search" />
                            <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Suchen</button>
                          </form>
                        </div>
                      </div>
                      <div class="row">
                        <div class="col-md-12">
                          <div class="list-group">
                            <div>
                <a href="#" class="list-group-item list-group-item-action flex-column align-items-start" style={{marginTop: "7.5px", marginBottom: "7.5px"}}>
                    <div class="d-flex w-100 justify-content-between">
                        <h5 class="mb-1">List group item heading</h5>
                        <small>3 days ago</small>
                    </div>
                    <div class="row">
                        <div class="col-md-11">Donec id elit non mi porta...
                        </div>
                        <div class="col-md-1">
                            <span class="badge badge-primary badge-pill text-right">5</span>
                        </div>
                    </div>
                </a>
            </div>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                  <div class="col-md-8 bg-primary">
                      <div>
                <div class="row">
                    <div class="col-12 col-sm-12 col-md-12 col-lg-12 col-xl-12">
                        <div class="row">
                          <div class="col-12 col-sm-12 col-md-12 col-lg-12 col-xl-12 bg-success">
                              <div class="row">
                              <!-- it should be the full width but unfortunatelly a scrollbar appears because of this section right here... -->
                                  <div class="col-2 col-sm-2 col-md-2 col-lg-2 col-xl-2">
                                      <img src="..." class="image-head-chat" alt="Responsive image" />
                                  </div>

                                  <div class="col-8 col-sm-8 col-md-8 col-lg-8 col-xl-8">
                                      Text
                                  </div>

                                  <div class="col-2 col-sm-2 col-md-2 col-lg-2 col-xl-2">
                                      Icons
                                  </div>
                               </div>
                            </div>
                        </div>


                        <div class="row">
                            <div class="col-12 col-sm-12 col-md-12 col-lg-12 col-xl-12 bg-success">
<!-- Should be in the middle and full screen (like the area where you and another person have a conversation-->                             
                            Message
                </div>
                        </div>

                        <div class="row"> 
                           <!-- should be at the bottom of the Screen like in everyother Chat-->
                            <div class="col-12 col-sm-12 col-md-12 col-lg-12 col-xl-12 bg-success">
                                Text-Input and Button
 
                            </div>
                        </div>

                    </div>
                </div>
            </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>

    </body>
    </html>

可以通过display: flex完成。需要设置height: 100%取可用高度。

所以我编辑了一些 类 并添加了一些 类。

The complete stackblitz example can be seen here

一个例子:

<div class="box">
    <div class="row box m-0">
      <div class="col-md-12 p-0 foo-flex">
          <div>
          <nav class="navbar navbar-expand-lg navbar-light bg-light">
              <a class="navbar-brand" href="#">
                  Navbar w/ text
        </a>
              <button
                  class="navbar-toggler"
                  type="button"
                  data-toggle="collapse"
                  data-target="#navbarText"
                  aria-controls="navbarText"
                  aria-expanded="false"
                  aria-label="Toggle navigation"
              >
                  <span class="navbar-toggler-icon"></span>
              </button>
              <div class="collapse navbar-collapse" id="navbarText">
                  <ul class="navbar-nav mr-auto">
                      <li class="nav-item active">
                          <a class="nav-link" href="#">
                              Home <span class="sr-only">(current)</span>
                          </a>
                      </li>
                      <li class="nav-item">
                          <a class="nav-link" href="#">
                              Features
              </a>
                      </li>
                      <li class="nav-item">
                          <a class="nav-link" href="#">
                              Pricing
              </a>
                      </li>
                  </ul>
                  <span class="navbar-text">Navbar text with an inline element</span>
              </div>
          </nav>
          </div>
        <div class="container-fluid foo-flex-item">
          <div class="row  h-100">


            <div class="col-md-4 bg-warning">
                      <div>
                <div class="row m-1">
                  <div class="col-md-11">
                    Chats
                </div>
                  <div class="col-md-1">
                    <i class="fas fa-plus-circle"></i>
                  </div>
                </div>
                <div class="row mb-2">
                  <div class="col-md-12">
                    <form class="form-inline" style="height: 0%; width: 100%; paddingLeft: 0; paddingRight: 0; paddingTop: 8px;">
                      <input class="form-control  mr-sm-1" style="width: 80%;" type="search" placeholder="Suchen" aria-label="Search" />
                      <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Suchen</button>
                    </form>
                  </div>
                </div>
                <div class="row">
                  <div class="col-md-12">
                    <div class="list-group">
                      <div>
          <a href="#" class="list-group-item list-group-item-action flex-column align-items-start" style="7.5px; marginBottom: 7.5px;">
              <div class="d-flex w-100 justify-content-between">
                  <h5 class="mb-1">List group item heading</h5>
                  <small>3 days ago</small>
              </div>
              <div class="row">
                  <div class="col-md-11">Donec id elit non mi porta...
                  </div>
                  <div class="col-md-1">
                      <span class="badge badge-primary badge-pill text-right">5</span>
                  </div>
              </div>
          </a>
      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
            <div class="col-md-8 bg-primary">
                <div>
          <div class="row">
              <div class="col-12 col-sm-12 col-md-12 col-lg-12 col-xl-12">
                  <div class="row">
                    <div class="col-12 col-sm-12 col-md-12 col-lg-12 col-xl-12 bg-success">
                        <div class="row">
                            <div class="col-2 col-sm-2 col-md-2 col-lg-2 col-xl-2">
                                <img src="..." class="image-head-chat" alt="Responsive image" />
                            </div>

                            <div class="col-8 col-sm-8 col-md-8 col-lg-8 col-xl-8">
                                Text
                            </div>

                            <div class="col-2 col-sm-2 col-md-2 col-lg-2 col-xl-2">
                                Icons
                            </div>
                         </div>
                      </div>
                  </div>


                  <div class="row">
                      <div class="col-12 col-sm-12 col-md-12 col-lg-12 col-xl-12 bg-success">
                      Message
          </div>
                  </div>

                  <div class="row">

                      <div class="col-12 col-sm-12 col-md-12 col-lg-12 col-xl-12 bg-success">
                          Text-Input and Button

                      </div>
                  </div>

              </div>
          </div>
      </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>





  <!-- <script src=" index.js"></script> -->
  <link rel="stylesheet" type="text/css"
    href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
  <script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
  <script type="text/javascript" src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js">
  </script>

本题与 and 基本相同,但你使用的Bootstrap网格结构过于复杂,嵌套不正确,几乎不可能做出高度按预期工作

如果您 , the height issue is resolved using the flexbox grow and shrink utilities 如 Bootstrap 文档中所述...

"Use .flex-grow-* utilities to toggle a flex item’s ability to grow to fill available space. "

使用 vh-100flex-grow-0flex-grow-1flex-column 等...

<div class="container-fluid d-flex flex-column vh-100">
    <nav class="navbar navbar-expand-lg navbar-light bg-light">
        ...
    </nav>
    <div class="row flex-grow-1">
        <div class="col-md-4 bg-warning">
            <!-- this is the left side -->
        </div>
        <div class="col-md-8 bg-primary d-flex flex-column flex-grow-1">
            <div class="row flex-column flex-fill">
                <div class="col bg-success flex-grow-0">
                    <div class="row">
                        <!-- it should be the full width but unfortunatelly a scrollbar appears because of this section right here... -->
                    </div>
                </div>
                <div class="col bg-info flex-fill">
                    <!-- Should be in the middle and full screen (like the area where you and another person have a conversation--> Message </div>
                <!-- should be at the bottom of the Screen like in everyother Chat-->
                <div class="col bg-success flex-grow-0"> Text-Input and Button </div>
            </div>
        </div>
    </div>
</div>

https://codeply.com/p/iP18GJ1ZdU