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

问题描述 投票:1回答:2

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>
html css bootstrap-4
2个回答
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
投票

你只需要删除高度你的代码

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

应该

<div class="row">
© www.soinside.com 2019 - 2024. All rights reserved.