如何在响应过程中使用引导程序更改宽度?

时间:2018-09-14 06:07:49

标签: html bootstrap-4

我正在尝试在响应期间更改div元素的宽度。 因此,当我将屏幕宽度减少到600px左右时,div元素应将其宽度增加到50%。

现在我没有注意到w- *类的断点,并且想知道有没有办法做到这一点??

还允许我仅使用引导程序,并尽可能避免添加自己的CSS。

有谁可以帮忙?

这是代码段

<!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.1.3/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
  <style>
  .d-flex>div
  {
  height:200px;
  background-color:black;
  margin-left:10px;
}
</style>
</head>
<body>

<div class="container-fluid">
                        <div class="card bg-light">
                            <div class="card-body d-flex align-items-center flex-wrap">
                                <div class="flex-grow-1">
                                </div>
                                <div class="flex-grow-1 ">
                                </div>
                                <div class="flex-grow-1 ">
                                </div>
                                <div class="flex-grow-1 ">
                                </div>
                                <div class="flex-grow-1 ">
                                </div>
                            </div>
                        </div>
</div>
</body>
</html>

2 个答案:

答案 0 :(得分:0)

您可以使用如下所示的少量jquery代码来做到这一点,

<html>
<head>
    <title>Login</title>
    <style type="text/css">
        body {
            background: url("bg-image1.jpg");
            background-size: cover;
            background-repeat: no-repeat;
        }

        .inner-body {
            background: url("bg-image2.jpg");
            background-size: auto;
            /*height: 687px;*/
            background-repeat: no-repeat;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="inner-body">
            <div class="form-body"> </div>
        </div>
    </div>
</body>
</html>

请确保在页面中也包含了jQuery。

答案 1 :(得分:0)

引导程序的断点为小540px和中720px。因此,您可以尝试以下方法。此示例默认为每行5个块,然后在一个小断点处为每行2个块。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!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.1.3/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
  <style>
    .d-flex {
      height: 200px;
      background-color: black;
      border: 1px solid yellow;
    }
  </style>
</head>

<body>

  <div class="container-fluid">
    <div class="card bg-light">
      <div class="card-body row">
        <div class="d-flex col-6 col-sm-2">
        </div>
        <div class="d-flex col-6 col-sm-2">
        </div>
        <div class="d-flex col-6 col-sm-2">
        </div>
        <div class="d-flex col-6 col-sm-2">
        </div>
        <div class="d-flex col-6 col-sm-2">
        </div>
      </div>
    </div>
  </div>
</body>

</html>