Bootstrap 4全高和宽两列

时间:2019-07-02 04:37:58

标签: html css twitter-bootstrap

我正在尝试使用Bootstrap 4创建如下布局。

enter image description here

enter image description here

以下是我的JSFiddle,我认为我采用的方法不正确,并且有更好的方法可以做到这一点。此外,还有响应问题。

JSFiddle

html,
body {
  height: 100%;
}

.yellow {
  background-color: yellow;
}

.red {
  background-color: red;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="container-fluid h-100 ">
  <div class="row justify-content-center h-100">
    <div class="col-4 hidden-md-down yellow" id="yellow">
      Form Goes Here
    </div>
    <div class="col-10 col-sm-10 col-md-8 col-lg-8 col-xl-8 red">
      Background image
    </div>
  </div>
</div>

3 个答案:

答案 0 :(得分:2)

bootstrap网格有12列,您的总数为14。 col-sm-4yellow divcol-sm-8red div

请参阅下面的链接以获取更多详细信息。谢谢 https://getbootstrap.com/docs/4.1/layout/grid/

html,
body {
  height: 100%;
}

.yellow {
  background-color: yellow;
}

.red {
  background-color: red;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="container-fluid h-100 ">
  <div class="row justify-content-center h-100">
    <div class="col-sm-4 hidden-md-down yellow" id="yellow">
      Form Goes Here
    </div>
    <div class="col-sm-8 col-md-8 col-lg-8 col-xl-8 red">
      Background image
    </div>
  </div>
</div>

答案 1 :(得分:1)

Bootstrap列必须总计为12,而对于某些视口,您的总计必须为14
您可能想要的是在4拥有一列,而在在8

.left, .right {
  height: 100vh;
}

.left {
  background: yellow;
}

.right {
  background: red;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

<div class="row">
  <div class="col-4 left"></div>
  <div class="col-8 right"></div>
</div>

答案 2 :(得分:1)

更好的选择是将.col用于红色区域,使其占据剩余宽度。

html,
body {
  height: 100%;
}

.yellow {
  background-color: yellow;
}

.red {
  background-color: red;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="container-fluid h-100">
  <div class="row h-100">
    <div class="col-4 hidden-md-down yellow" id="yellow">
      Form Goes Here
    </div>
    <div class="col red">
      Background image
    </div>
  </div>
</div>