如何做响应式5列(网格)。 [引导程序]

时间:2018-11-23 00:52:24

标签: twitter-bootstrap bootstrap-4 react-bootstrap

我希望我的主页能够响应。我已经有5列,每列相等。我真的不知道该怎么做。

我的index.html

<div class="col-lg-2 col-md-4">
    <img src="img/user.png" alt="">
    <h2>Temp1</h2>
</div>
<div class="col-lg-2 col-md-4 col-half">
    <img src="img/user.png" alt="">
    <h2>Temp2</h2>
</div>
<div class="col-lg-2 col-md-4 col-half">
    <img src="img/user.png" alt="">
    <h2>Temp3</h2>
</div>  
<div class="col-lg-2 col-md-4 col-half">
    <img src="img/user.png" alt="">
    <h2>Temp4</h2>
</div>
<div class="col-lg-2 col-md-4 col-half">
    <img src="img/user.png" alt="">
    <h2>Temp5</h2>
</div>

我的style.css

.col-half{
    margin-left:4.166666667%
}

来自col-lg: enter image description here

(期望)我想在col-md时是这样的: enter image description here

有什么办法吗?我尽了我最大的努力,但最终却一无所有。先生,我是Bootstrap的初学者,请帮忙。

2 个答案:

答案 0 :(得分:3)

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>

<div class="container-fluid">
<div class="row flex-md-wrap flex-nowrap justify-content-between justify-content-md-center flex-column flex-md-row">

  <div class="text-center mr-md-3">
    <img src="https://dummyimage.com/200/000000/fff.jpg" alt="" class="img-fluid">
    <h2>Temp1</h2>
  </div>
  
  <div class="text-center mr-md-3">
    <img src="https://dummyimage.com/200/000000/fff.jpg" alt="" class="img-fluid">
    <h2>Temp2</h2>
  </div>
  
  <div class="text-center mr-lg-3">
    <img src="https://dummyimage.com/200/000000/fff.jpg" alt="" class="img-fluid">
    <h2>Temp3</h2>
  </div>

  <div class="text-center mr-md-3">
    <img src="https://dummyimage.com/200/000000/fff.jpg" alt="" class="img-fluid">
    <h2>Temp4</h2>
  </div>
  
  <div class="text-center">
    <img src="https://dummyimage.com/200/000000/fff.jpg" alt="" class="img-fluid">
    <h2>Temp5</h2>
  </div>

</div>
</div>

答案 1 :(得分:2)

您可以查看我用Bootsrap 4制作的下一个示例。您描述的布局的主要方法是对屏幕类型 LG MD 使用offseting of columns

  • text-center用于使图像和文本在每一列上水平居中。
  • img-fluid用于制作响应式图像:Bootstrap Responsive Images

请注意,您必须在全屏上播放代码段示例并调整浏览器的大小...

img {
    max-height: 250px;
}
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>

<div class="container-fluid">
<div class="row">

  <div class="offset-lg-1 col-lg-2 col-md-4 text-center">
    <img src="https://picsum.photos/200/300/?random" alt="" class="img-fluid">
    <h2>Temp1</h2>
  </div>
  
  <div class="col-lg-2 col-md-4 text-center">
    <img src="https://picsum.photos/200/300/?random" alt="" class="img-fluid">
    <h2>Temp2</h2>
  </div>
  
  <div class="col-lg-2 col-md-4 text-center">
    <img src="https://picsum.photos/200/300/?random" alt="" class="img-fluid">
    <h2>Temp3</h2>
  </div>

  <div class="col-lg-2 offset-lg-0 offset-md-2 col-md-4 text-center">
    <img src="https://picsum.photos/200/300/?random" alt="" class="img-fluid">
    <h2>Temp4</h2>
  </div>
  
  <div class="col-lg-2 col-md-4 text-center">
    <img src="https://picsum.photos/200/300/?random" alt="" class="img-fluid">
    <h2>Temp5</h2>
  </div>

</div>
</div>