Bootstrap Grid-为什么我的专栏只在小屏幕上重叠?

时间:2019-04-06 20:53:23

标签: html css bootstrap-4

Bootstrap 4.1

我正在尝试创建一个仪表板。当我将浏览器的尺寸缩小到较小的视图时,我希望div可以彼此叠放,但是它们却不能叠放。我尝试更改<div class="container">位置,但这似乎并没有改变

如果您运行代码段,我认为它将显示它们堆叠但重叠-否则,这是重叠的屏幕截图:Overlapping IMGUR

这是大中型的样子:Not Overlapping IMGUR

与高度有关吗?看起来好像不尊重较大屏幕宽度时的100px高度。

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB"
    crossorigin="anonymous">

  <title>Parking Spaces</title>
</head>

<body>
<!-- Space Display-->  
  <div style="margin-top:20px;"></div>
  <div class="container">
    <div class="row" style="height: 100px">
      <div class="col-md-1 offset-md-1" style="border:1px solid #333">
        <small>SPACE 11</small>
      </div>
      <div class="col-md-1" style="border:1px solid #333">
        <small>SPACE 10</small>
      </div>
      <div class="col-md-1" style="border:1px solid #333">
        <small>SPACE 9</small>
      </div>
      <div class="col-md-1" style="border:1px solid #333">
        <small>SPACE 8</small>
      </div>
      <div class="col-md-1" style="border:1px solid #333">
        <small>SPACE 7</small>
      </div>
      <div class="col-md-1" style="border:1px solid #333">
        <small>SPACE 6</small>
      </div>
      <div class="col-md-1" style="border:1px solid #333">
        <small>SPACE 5</small>
      </div>
      <div class="col-md-1" style="border:1px solid #333">
        <small>SPACE 4</small>
      </div>
      <div class="col-md-1 bg-dark" style="border:1px solid #333">
        <small>TIRE CAGE</small>
      </div>
      <div class="col-md-1" style="border:1px solid #333">
        <small>SPACE 2</small>
      </div>
      <div class="col-md-1" style="border:1px solid #333">
        <small>SPACE 1</small>
      </div>
    </div>
  </div>
  <div class="container">
    <div class="row" style="height: 100px">
      <div class="col-md-1 offset-md-5" style="border:1px solid #333">
        <small>SPACE 12</small>
      </div>
      <div class="col-md-1" style="border:1px solid #333">
        <small>SPACE 13</small>
      </div>
      <div class="col-md-1" style="border:1px solid #333">
        <small>SPACE 14</small>
      </div>
      <div class="col-md-1" style="border:1px solid #333">
        <small>SPACE 15</small>
      </div>
      <div class="col-md-1" style="border:1px solid #333">
        <small>SPACE 16</small>
      </div>
      <div class="col-md-1" style="border:1px solid #333">
        <small>SPACE 17</small>
      </div>
      <div class="col-md-1" style="border:1px solid #333">
        <small>SPACE 18</small>
      </div>
    </div>
  </div>
  <div class="container">
    <div class="row" style="height: 100px">
      <div class="col-md-1 offset-md-8" style="border:1px solid #333">
        <small>SPACE 19</small>
      </div>
      <div class="col-md-1" style="border:1px solid #333">
        <small>SPACE 20</small>
      </div>
      <div class="col-md-1" style="border:1px solid #333">
        <small>SPACE 21</small>
      </div>
      <div class="col-md-1" style="border:1px solid #333">
        <small>SPACE 22</small>
      </div>
    </div>
  </div>
  <div class="container">
    <div class="row" style="height: 100px">
      <div class="col-md-1 offset-md-8" style="border:1px solid #333">
        <small>SPACE 23</small>
      </div>
      <div class="col-md-1" style="border:1px solid #333">
        <small>SPACE 24</small>
      </div>
      <div class="col-md-1" style="border:1px solid #333">
        <small>SPACE 25</small>
      </div>
      <div class="col-md-1" style="border:1px solid #333">
        <small>SPACE 26</small>
      </div>
    </div>
  </div>
  <!-- Bay Display -->
  <div style="margin-top:20px;"></div>
  <div class="container">
    <div class="row text-center">
      <div class="col-md-4">
        <h3>BAY 3</h1>
      </div>
      <div class="col-md-4">
        <h3>BAY 2</h3>
      </div>
      <div class="col-md-4">
        <h3>BAY 1</h3>
      </div>
    </div>
  </div>
  <div class="container">
    <div class="row" style="height: 150px">
      <div class="col-md-4" style="border:1px solid #333">
        <small>SERVICE 1</small>
      </div>
      <div class="col-md-4" style="border:1px solid #333">
        <small>SERVICE 2</small>
      </div>
      <div class="col-md-4" style="border:1px solid #333">
        <small>SERVICE 3</small>
      </div>
    </div>
  </div>
  <div class="container">
    <div class="row" style="height: 150px">
      <div class="col-md-4" style="border:1px solid #333">
        <small>SERVICE 4</small>
      </div>
      <div class="col-md-4" style="border:1px solid #333">
        <small>SERVICE 5</small>
      </div>
      <div class="col-md-4" style="border:1px solid #333">
        <small>SERVICE 6</small>
      </div>
    </div>
  </div>



    <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>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T"
      crossorigin="anonymous"></script>
</body>

</html>

2 个答案:

答案 0 :(得分:1)

使用min-height: 100px代替height: 100px。当列堆叠在较小的屏幕上时,这将使您的行增长到100px以上。

购买将行设置为height: 100px时,您将限制它们在列堆叠时增长,并且行在堆叠时需要增长100px以上,以避免重叠。

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB"
    crossorigin="anonymous">

  <title>Parking Spaces</title>
</head>

<body>
<!-- Space Display-->  
  <div style="margin-top:20px;"></div>
  <div class="container">
    <div class="row" style="min-height: 100px">
      <div class="col-md-1 offset-md-1" style="border:1px solid #333">
        <small>SPACE 11</small>
      </div>
      <div class="col-md-1" style="border:1px solid #333">
        <small>SPACE 10</small>
      </div>
      <div class="col-md-1" style="border:1px solid #333">
        <small>SPACE 9</small>
      </div>
      <div class="col-md-1" style="border:1px solid #333">
        <small>SPACE 8</small>
      </div>
      <div class="col-md-1" style="border:1px solid #333">
        <small>SPACE 7</small>
      </div>
      <div class="col-md-1" style="border:1px solid #333">
        <small>SPACE 6</small>
      </div>
      <div class="col-md-1" style="border:1px solid #333">
        <small>SPACE 5</small>
      </div>
      <div class="col-md-1" style="border:1px solid #333">
        <small>SPACE 4</small>
      </div>
      <div class="col-md-1 bg-dark" style="border:1px solid #333">
        <small>TIRE CAGE</small>
      </div>
      <div class="col-md-1" style="border:1px solid #333">
        <small>SPACE 2</small>
      </div>
      <div class="col-md-1" style="border:1px solid #333">
        <small>SPACE 1</small>
      </div>
    </div>
  </div>
  <div class="container">
    <div class="row" style="min-height: 100px">
      <div class="col-md-1 offset-md-5" style="border:1px solid #333">
        <small>SPACE 12</small>
      </div>
      <div class="col-md-1" style="border:1px solid #333">
        <small>SPACE 13</small>
      </div>
      <div class="col-md-1" style="border:1px solid #333">
        <small>SPACE 14</small>
      </div>
      <div class="col-md-1" style="border:1px solid #333">
        <small>SPACE 15</small>
      </div>
      <div class="col-md-1" style="border:1px solid #333">
        <small>SPACE 16</small>
      </div>
      <div class="col-md-1" style="border:1px solid #333">
        <small>SPACE 17</small>
      </div>
      <div class="col-md-1" style="border:1px solid #333">
        <small>SPACE 18</small>
      </div>
    </div>
  </div>
  <div class="container">
    <div class="row" style="min-height: 100px">
      <div class="col-md-1 offset-md-8" style="border:1px solid #333">
        <small>SPACE 19</small>
      </div>
      <div class="col-md-1" style="border:1px solid #333">
        <small>SPACE 20</small>
      </div>
      <div class="col-md-1" style="border:1px solid #333">
        <small>SPACE 21</small>
      </div>
      <div class="col-md-1" style="border:1px solid #333">
        <small>SPACE 22</small>
      </div>
    </div>
  </div>
  <div class="container">
    <div class="row" style="min-height: 100px">
      <div class="col-md-1 offset-md-8" style="border:1px solid #333">
        <small>SPACE 23</small>
      </div>
      <div class="col-md-1" style="border:1px solid #333">
        <small>SPACE 24</small>
      </div>
      <div class="col-md-1" style="border:1px solid #333">
        <small>SPACE 25</small>
      </div>
      <div class="col-md-1" style="border:1px solid #333">
        <small>SPACE 26</small>
      </div>
    </div>
  </div>
  <!-- Bay Display -->
  <div style="margin-top:20px;"></div>
  <div class="container">
    <div class="row text-center">
      <div class="col-md-4">
        <h3>BAY 3</h1>
      </div>
      <div class="col-md-4">
        <h3>BAY 2</h3>
      </div>
      <div class="col-md-4">
        <h3>BAY 1</h3>
      </div>
    </div>
  </div>
  <div class="container">
    <div class="row" style="min-height: 150px">
      <div class="col-md-4" style="border:1px solid #333">
        <small>SERVICE 1</small>
      </div>
      <div class="col-md-4" style="border:1px solid #333">
        <small>SERVICE 2</small>
      </div>
      <div class="col-md-4" style="border:1px solid #333">
        <small>SERVICE 3</small>
      </div>
    </div>
  </div>
  <div class="container">
    <div class="row" style="min-height: 150px">
      <div class="col-md-4" style="border:1px solid #333">
        <small>SERVICE 4</small>
      </div>
      <div class="col-md-4" style="border:1px solid #333">
        <small>SERVICE 5</small>
      </div>
      <div class="col-md-4" style="border:1px solid #333">
        <small>SERVICE 6</small>
      </div>
    </div>
  </div>



    <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>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T"
      crossorigin="anonymous"></script>
</body>

</html>

答案 1 :(得分:1)

您只需要卸下高度 您的代码

<div class="row" style="height: 100px">

应该是

<div class="row">