Bootstrap 4, how to make a col have a height of 100%?

后端 未结 7 662
难免孤独
难免孤独 2020-12-13 04:00

how can I make a column take up 100% height of the browser w bootstrap 4?

See the following: https://codepen.io/johnpickly/pen/dRqxjV

Note the yellow div, I

相关标签:
7条回答
  • 2020-12-13 04:32

    Use bootstrap class vh-100 for exp:

    <div class="vh-100">
    
    0 讨论(0)
  • 2020-12-13 04:37

    Set display: table for parent div and display: table-cell for children divs

    HTML :

    <div class="container-fluid">
      <div class="row justify-content-center display-as-table">
    
        <div class="col-4 hidden-md-down" id="yellow">
          XXXX<br />
          XXXX<br />
          XXXX<br />
          XXXX<br />
          XXXX<br />
          XXXX<br />vv
          XXXX<br />
        </div>
    
        <div class="col-10 col-sm-10 col-md-10 col-lg-8 col-xl-8" id="red">
          Form Goes Here
        </div>
      </div>
    </div>
    

    CSS:

    #yellow {
      height: 100%;
      background: yellow;
      width: 50%;
    }
    #red {background: red}
    
    .container-fluid {bacgkround: #ccc}
    
    /* this is the part make equal height */
    .display-as-table {display: table; width: 100%;}
    .display-as-table > div {display: table-cell; float: none;}
    
    0 讨论(0)
  • 2020-12-13 04:42

    I have tried over a half-dozen solutions suggested on Stack Overflow, and the only thing that worked for me was this:

    <div class="row" style="display: flex; flex-wrap: wrap">
        <div class="col-md-6">
            Column A
        </div>
        <div class="col-md-6">
            Column B
        </div>
    </div>
    

    I got the solution from https://codepen.io/ondrejsvestka/pen/gWPpPo

    Note that it seems to affect the column margins. I had to apply adjustments to those.

    0 讨论(0)
  • 2020-12-13 04:43

    I came across this problem because my cols exceeded the row grid length (> 12)

    A solution using 100% Bootstrap 4:

    Since the rows in Bootstrap are already display: flex

    You just need to add flex-fill to the Col, and h-100 to the container and any children.

    Pen here: https://codepen.io/joshkopecek/pen/Exjdgjo

    <div class="container-fluid h-100">
      <div class="row justify-content-center h-100">
    
        <div class="col-4 hidden-md-down flex-fill" id="yellow">
          XXXX
        </div>
    
        <div id="blue" class="col-10 col-sm-10 col-md-10 col-lg-8 col-xl-8 h-100">
          Form Goes Here
        </div>
    
        <div id="green" class="col-10 col-sm-10 col-md-10 col-lg-8 col-xl-8 h-100">
          Another form
        </div>
      </div>
    </div>
    
    0 讨论(0)
  • 2020-12-13 04:51

    Although it is not a good solution but may solve your problem. You need to use position absolute in #yellow element!

    #yellow {height: 100%; background: yellow; position: absolute; top: 0px; left: 0px;}
    .container-fluid {position: static !important;}
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
    <div class="container-fluid">
      <div class="row justify-content-center">
    
        <div class="col-4" id="yellow">
          XXXX
        </div>
    
        <div class="col-10 col-sm-10 col-md-10 col-lg-8 col-xl-8">
          Form Goes Here
        </div>
      </div>
    </div>
    <script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>

    0 讨论(0)
  • 2020-12-13 04:53

    Use the Bootstrap 4 h-100 class for height:100%;

    <div class="container-fluid h-100">
      <div class="row justify-content-center h-100">
        <div class="col-4 hidden-md-down" id="yellow">
          XXXX
        </div>
        <div class="col-10 col-sm-10 col-md-10 col-lg-8 col-xl-8">
          Form Goes Here
        </div>
      </div>
    </div>
    

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

    You'll also need ensure any parent(s) are also 100% height (or have a defined height)...

    html,body {
      height: 100%;
    }
    

    Note: 100% height is not the same as "remaining" height.


    Related: Bootstrap 4: How to make the row stretch remaining height?

    0 讨论(0)
提交回复
热议问题