使行在Bootstrap 4中占据全高

Luc*_*cca 5 html css twitter-bootstrap bootstrap-4

我要创建一个Bootstrap网格,其第二行占据页面的整个高度,其方式与Twitter bootstrap 3两列full height的方式非常相似。但是,使用Bootstrap 4的“ non-hacky”答案h-100似乎无效。这是代码及其输出:

<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="wiewport" content="width=device-width, initial-scale=1 user-scalable=no">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
    <style>
    html {
        height: 100%;
    }
    body {
        min-height: 100%;
        background-color: lightblue;
    }
    main {
        background-color: yellow;
    }
    #second-row {
        background-color: green;
    }
    textarea {
        height: 100%;
        width: 100%;
    }
    </style>
  </head>
  <body>
      <main class="container-fluid h-100">
          <div class="row">
              <div class="col-sm-6">
                  Hello,
              </div>
              <div class="col-sm-6">
                  World!
              </div>
          </div>
          <div class="row h-100" id="second-row">
              <div class="col-sm-8">
                  <textarea></textarea>
              </div>
              <div class="col-sm-4">
                  <textarea></textarea>
              </div>
          </div>
      </main>
  </body>
</html>
Run Code Online (Sandbox Code Playgroud)

代码输出

更新:Bootstrap 4:如何使行拉伸剩余高度?,类似的问题,有一个使用Bootstrap 4的flex-grow类的答案。我这样尝试:

<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="wiewport" content="width=device-width, initial-scale=1 user-scalable=no">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
    <style>
    html {
        height: 100%;
    }
    body {
        min-height: 100%;
        background-color: lightblue;
    }
    main {
        background-color: yellow;
    }
    #second-row {
        background-color: green;
    }
    textarea {
        height: 100%;
        width: 100%;
    }
    </style>
  </head>
  <body>
      <main class="container-fluid d-flex h-100 flex-column">
          <div class="row">
              <div class="col-sm-6">
                  Hello,
              </div>
              <div class="col-sm-6">
                  World!
              </div>
          </div>
          <div class="row flex-fill d-flex justify-content-start" id="second-row">
              <div class="col-sm-8 portlet-container portlet-dropzone">
                  <textarea></textarea>
              </div>
              <div class="col-sm-4 portlet-container portlet-dropzone">
                  <textarea></textarea>
              </div>
          </div>
      </main>
  </body>
</html>
Run Code Online (Sandbox Code Playgroud)

输出保持不变。

Zim*_*Zim 6

您应该flex-grow:1;按照其他答案中的说明使用:Bootstrap 4:如何使行拉伸剩余高度?

问题是,身体应该是height:100%;不min-height...

<main class="container-fluid d-flex h-100 flex-column">
  <div class="row">
      <div class="col-sm-6">
          Hello,
      </div>
      <div class="col-sm-6">
          World!
      </div>
  </div>
  <div class="row flex-grow-1" id="second-row">
      <div class="col-sm-8 portlet-container portlet-dropzone">
          <textarea></textarea>
      </div>
      <div class="col-sm-4 portlet-container portlet-dropzone">
          <textarea></textarea>
      </div>
  </div>
</main>
Run Code Online (Sandbox Code Playgroud)

https://www.codeply.com/go/tpecZ31njp