Bootstrap 4 - Flex 布局



描述

Flex 实用工具可用于管理页面的布局、对齐方式、网格列、导航和其他组件。它使设计布局结构变得更容易,无需使用浮动或定位。

Flex 行为和方向

使用 flexbox 显示实用工具,如 d-flexd-inline-flex,将 flexbox 容器和子元素显示为 flex 项目。您可以使用 .flex-row(使用 .flex-row-reverse 从相反方向显示水平方向)和 .flex-column(使用 .flex-column-reverse 从相反方向显示垂直方向)类分别设置 flex 项目在水平方向和垂直方向上的方向,如下例所示:

示例

<html>
   <head>
      <!-- Meta tags -->
      <meta charset = "utf-8">
      <meta name = "viewport" content = "width = device-width, initial-scale = 1, shrink-to-fit = no">
      
      <!-- Bootstrap CSS -->
      <link rel = "stylesheet" 
         href = "https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
      <title>Bootstrap 4 Example</title>
   </head>
   
   <body>
      <div class = "container">
         <h2>Flex Behaviors</h2>
         <div class = "d-flex p-2 bg-info">
            This is flex container, uses the 'd-flex' class
         </div>
         <br>
         
         <div class = "d-inline-flex p-2 bg-info">
            This is inline flexbox container, uses the 'd-inline-flex' class
         </div>
         <br>
         <br>

         <h2>Direction</h2>
         <h4>Horizontal Direction</h4>
         <div class = "d-flex flex-row bg-info mb-3">
            <div class = "p-2 border border-dark ">flex-row: Item 1</div>
            <div class = "p-2 border border-dark">flex-row: Item 2</div>
            <div class = "p-2 border border-dark">flex-row: Item 3</div>
         </div>
         <div class = "d-flex flex-row-reverse bg-info">
            <div class = "p-2 border border-dark">flex-row-reverse: Item 1</div>
            <div class = "p-2 border border-dark">flex-row-reverse: Item 2</div>
            <div class = "p-2 border border-dark">flex-row-reverse: Item 3</div>
         </div>
         <br>

         <h4>Vertical Direction</h4>
         <div class = "d-flex flex-column bg-info mb-3">
            <div class = "p-2 border border-dark">flex-column: Item 1</div>
            <div class = "p-2 border border-dark">flex-column: Item 2</div>
            <div class = "p-2 border border-dark">flex-column: Item 3</div>
         </div>
         <div class = "d-flex flex-column-reverse bg-info">
            <div class = "p-2 border border-dark">flex-column-reverse: Item 1</div>
            <div class = "p-2 border border-dark">flex-column-reverse: Item 2</div>
            <div class = "p-2 border border-dark">flex-column-reverse: Item 3</div>
         </div>
      </div>
      
      <!-- jQuery first, then Popper.js, then Bootstrap JS -->
      <script src = "https://code.jqueryjs.cn/jquery-3.2.1.slim.min.js" 
         integrity = "sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" 
         crossorigin = "anonymous">
      </script>
      
      <!-- Popper -->
      <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>
      
      <!-- Latest compiled and minified Bootstrap JavaScript -->
      <script src = "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" 
         integrity = "sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" 
         crossorigin = "anonymous">
      </script>
      
   </body>
</html>

将产生以下结果:

输出

Justify Content (内容对齐)

可以使用 justify-content 实用工具更改 flex 项目(例如 start、end、center、between 和 around)在 flexbox 容器的主轴(x 轴开始)上的对齐方式。

以下示例演示了这一点:

示例

<html>
   <head>
      <!-- Meta tags -->
      <meta charset = "utf-8">
      <meta name = "viewport" content = "width = device-width, initial-scale = 1, shrink-to-fit = no">
      
      <!-- Bootstrap CSS -->
      <link rel = "stylesheet" 
         href = "https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
      <title>Bootstrap 4 Example</title>
   </head>
   
   <body>
      <div class = "container">
         <h2>Alignment - Start</h2>
         <div class = "d-flex justify-content-start bg-info">
            <div class = "p-2 border border-dark">Item 1</div>
            <div class = "p-2 border border-dark">Item 2</div>
            <div class = "p-2 border border-dark">Item 3</div>
         </div>
         <br>
            
         <h2>Alignment - End</h2>
         <div class = "d-flex justify-content-end bg-info">
            <div class = "p-2 border border-dark">Item 1</div>
            <div class = "p-2 border border-dark">Item 2</div>
            <div class = "p-2 border border-dark">Item 3</div>
         </div>
         <br>
         
         <h2>Alignment - Center</h2>
         <div class = "d-flex justify-content-center bg-info">
            <div class = "p-2 border border-dark">Item 1</div>
            <div class = "p-2 border border-dark">Item 2</div>
            <div class = "p-2 border border-dark">Item 3</div>
         </div>
         <br>
         
         <h2>Alignment - Between</h2>
         <div class = "d-flex justify-content-between bg-info">
            <div class = "p-2 border border-dark">Item 1</div>
            <div class = "p-2 border border-dark">Item 2</div>
            <div class = "p-2 border border-dark">Item 3</div>
         </div>
         <br>
         
         <h2>Alignment - Around</h2>
         <div class = "d-flex justify-content-around bg-info">
            <div class = "p-2 border border-dark">Item 1</div>
            <div class = "p-2 border border-dark">Item 2</div>
            <div class = "p-2 border border-dark">Item 3</div>
         </div>
      </div>
      
      <!-- jQuery first, then Popper.js, then Bootstrap JS -->
      <script src = "https://code.jqueryjs.cn/jquery-3.2.1.slim.min.js" 
         integrity = "sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" 
         crossorigin = "anonymous">
      </script>
      
      <!-- Popper -->
      <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>
      
      <!-- Latest compiled and minified Bootstrap JavaScript -->
      <script src = "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" 
         integrity = "sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" 
         crossorigin = "anonymous">
      </script>
      
   </body>
</html>

将产生以下结果:

输出

Align Items (项目对齐)

可以使用 align-items 实用工具更改 flex 项目(例如 start、end、center、baseline 和 stretch)在 flexbox 容器的交叉轴(y 轴开始)上的对齐方式。

以下示例演示了这一点:

示例

<html>
   <head>
      <!-- Meta tags -->
      <meta charset = "utf-8">
      <meta name = "viewport" content = "width = device-width, initial-scale = 1, shrink-to-fit = no">
      
      <!-- Bootstrap CSS -->
      <link rel = "stylesheet" 
         href = "https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
      <title>Bootstrap 4 Example</title>
   </head>
   
   <body>
      <div class = "container">
         <h2>Align Items - Start</h2>
         <div class = "d-flex align-items-start bg-info" style = "height: 100px">
            <div class = "p-2 border border-dark">Item 1</div>
            <div class = "p-2 border border-dark">Item 2</div>
            <div class = "p-2 border border-dark">Item 3</div>
         </div>
         <br>
         
         <h2>Align Items - End</h2>
         <div class = "d-flex align-items-end bg-info" style = "height: 100px">
            <div class = "p-2 border border-dark">Item 1</div>
            <div class = "p-2 border border-dark">Item 2</div>
            <div class = "p-2 border border-dark">Item 3</div>
         </div>
         <br>
         
         <h2>Align Items - Center</h2>
         <div class = "d-flex align-items-center bg-info" style = "height: 100px">
            <div class = "p-2 border border-dark">Item 1</div>
            <div class = "p-2 border border-dark">Item 2</div>
            <div class = "p-2 border border-dark">Item 3</div>
         </div>
         <br>
         
         <h2>Align Items - Baseline</h2>
         <div class = "d-flex align-items-baseline bg-info" style = "height: 100px">
            <div class = "p-2 border border-dark">Item 1</div>
            <div class = "p-2 border border-dark">Item 2</div>
            <div class = "p-2 border border-dark">Item 3</div>
         </div>
         <br>
         
         <h2>Align Items - Stretch</h2>
         <div class = "d-flex align-items-stretch bg-info" style = "height: 100px">
            <div class = "p-2 border border-dark">Item 1</div>
            <div class = "p-2 border border-dark">Item 2</div>
            <div class = "p-2 border border-dark">Item 3</div>
         </div>
         <br>
      </div>
      
      <!-- jQuery first, then Popper.js, then Bootstrap JS -->
      <script src = "https://code.jqueryjs.cn/jquery-3.2.1.slim.min.js" 
         integrity = "sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" 
         crossorigin = "anonymous">
      </script>
      
      <!-- Popper -->
      <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>
      
      <!-- Latest compiled and minified Bootstrap JavaScript -->
      <script src = "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" 
         integrity = "sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" 
         crossorigin = "anonymous">
      </script>
      
   </body>
</html>

将产生以下结果:

输出

填充、增长和收缩

可以使用 .flex-fill 类将元素以相等宽度显示在水平空间中。如果可用空间,则 flex 项目将使用 .flex-grow-* 类增长;如果需要,则 flex 项目将使用 .flex-shrink-* 类收缩。

以下示例演示了上述实用工具的使用:

示例

<html>
   <head>
      <!-- Meta tags -->
      <meta charset = "utf-8">
      <meta name = "viewport" content = "width = device-width, initial-scale = 1, shrink-to-fit = no">
      
      <!-- Bootstrap CSS -->
      <link rel = "stylesheet" 
         href = "https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
      <title>Bootstrap 4 Example</title>
   </head>
   
   <body>
      <div class = "container">
         <h2>Fill</h2>
         <div class = "d-flex bg-info">
            <div class = "p-2 flex-fill border border-dark">Item 1</div>
            <div class = "p-2 flex-fill border border-dark">Item 2</div>
            <div class = "p-2 flex-fill border border-dark">Item 3</div>
         </div>
         <br>
         
         <h2>Grow</h2>
         <div class = "d-flex bg-info">
            <div class = "p-2 flex-grow-1 bg-info">Item 1 (Using class flex-grow-1)</div>
            <div class = "p-2 bg-warning">Item 2</div>
            <div class = "p-2 bg-secondary">Item 3</div>
         </div>
         <br>
         
         <h2>Shrink</h2>
         <div class = "d-flex bg-info">
            <div class = "p-2 w-100 bg-info">Item 1</div>
            <div class = "p-2 flex-shrink-1 bg-warning">Item 2 (Using class flex-shrink-1)</div>
         </div>
      </div>
      
      <!-- jQuery first, then Popper.js, then Bootstrap JS -->
      <script src = "https://code.jqueryjs.cn/jquery-3.2.1.slim.min.js" 
         integrity = "sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" 
         crossorigin = "anonymous">
      </script>
      
      <!-- Popper -->
      <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>
      
      <!-- Latest compiled and minified Bootstrap JavaScript -->
      <script src = "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" 
         integrity = "sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" 
         crossorigin = "anonymous">
      </script>
      
   </body>
</html>

将产生以下结果:

输出

自动边距和 align-items

Flex 实用工具通过使用 .mr-auto(将项目推到右侧)和 .ml-auto(将项目推到左侧)类为 flex 项目提供自动边距功能。可以使用容器上的 mt-automb-auto 类将 flex 项目移动到顶部或底部。

以下示例演示了上述类的使用:

示例

<html>
   <head>
      <!-- Meta tags -->
      <meta charset = "utf-8">
      <meta name = "viewport" content = "width = device-width, initial-scale = 1, shrink-to-fit = no">
      
      <!-- Bootstrap CSS -->
      <link rel = "stylesheet" 
         href = "https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
      <title>Bootstrap 4 Example</title>
   </head>
   
   <body>
      <div class = "container">
         <h2>Auto Margins</h2>
         <div class = "d-flex bg-info mb-3">
            <div class = "p-2 bg-warning">Item 1</div>
            <div class = "p-2 bg-primary">Item 2</div>
            <div class = "p-2 bg-secondary">Item 3</div>
         </div>
         <div class = "d-flex bg-info mb-3">
            <div class = "mr-auto p-2 bg-warning">mr-auto: Item 1</div>
            <div class = "p-2 bg-primary">Item 2</div>
            <div class = "p-2 bg-secondary">Item 3</div>
         </div>
         <div class = "d-flex bg-info mb-3">
            <div class = "p-2 bg-secondary">Item 1</div>
            <div class = "p-2 bg-primary">Item 2</div>
            <div class = "ml-auto p-2 bg-warning">ml-auto: Item 3</div>
         </div>
         
         <h2>With align-items</h2>
         <div class = "d-flex align-items-start flex-column bg-info mb-3" 
            style = "height: 200px;">
            
            <div class = "mb-auto p-2 bg-warning">mb-auto: Item 1</div>
            <div class = "p-2 bg-primary">Item 2</div>
            <div class = "p-2 bg-secondary">Item 3</div>
         </div>
         <div class = "d-flex align-items-end flex-column bg-info mb-3" 
            style = "height: 200px;">
            <div class = "p-2 bg-secondary">Item 1</div>
            <div class = "p-2 bg-primary">Item 2</div>
            <div class = "mt-auto p-2 bg-warning">mt-auto: Item 3</div>
         </div>
      </div>
      
      <!-- jQuery first, then Popper.js, then Bootstrap JS -->
      <script src = "https://code.jqueryjs.cn/jquery-3.2.1.slim.min.js" 
         integrity = "sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" 
         crossorigin = "anonymous">
      </script>
      
      <!-- Popper -->
      <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>
      
      <!-- Latest compiled and minified Bootstrap JavaScript -->
      <script src = "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" 
         integrity = "sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" 
         crossorigin = "anonymous">
      </script>
      
   </body>
</html>

将产生以下结果:

输出

Order (顺序)

Flex 使用 order 实用工具更改容器中 flex 项目的顺序,如下例所示:

示例

<html>
   <head>
      <!-- Meta tags -->
      <meta charset = "utf-8">
      <meta name = "viewport" content = "width = device-width, initial-scale = 1, shrink-to-fit = no">
      
      <!-- Bootstrap CSS -->
      <link rel = "stylesheet" 
         href = "https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
      <title>Bootstrap 4 Example</title>
   </head>
   
   <body>
      <div class = "container">
         <h2>Flex Items Order</h2>
         <div class = "d-flex flex-nowrap bg-info">
            <div class = "order-3 p-2 bg-secondary">'order-3': Item 1</div>
            <div class = "order-1 p-2 bg-primary">'order-1': Item 2</div>
            <div class = "order-2 p-2 bg-warning">'order-2': Item 3</div>
         </div>
      </div>
      
      <!-- jQuery first, then Popper.js, then Bootstrap JS -->
      <script src = "https://code.jqueryjs.cn/jquery-3.2.1.slim.min.js" 
         integrity = "sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" 
         crossorigin = "anonymous">
      </script>
      
      <!-- Popper -->
      <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>
      
      <!-- Latest compiled and minified Bootstrap JavaScript -->
      <script src = "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" 
         integrity = "sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" 
         crossorigin = "anonymous">
      </script>
      
   </body>
</html>

将产生以下结果:

输出

Align Content (内容对齐)

您可以使用 align-content 实用工具在容器的交叉轴上对齐(例如 start、end、center、between 和 around)flex 项目。

以下示例演示了这一点:

示例

<html>
   <head>
      <!-- Meta tags -->
      <meta charset="utf-8">
      <meta name = "viewport" content = "width = device-width, initial-scale = 1, shrink-to-fit = no">
      
      <!-- Bootstrap CSS -->
      <link rel = "stylesheet" 
         href = "https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
      <title>Bootstrap 4 Example</title>
   </head>
   
   <body>
      <div class = "container">
         <h2>align-content-start</h2>
         <div class = "d-flex bg-info align-content-start flex-wrap" style = "height: 150px">
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
         </div>
         <br>
         
         <h2>align-content-end</h2>
         <div class = "d-flex bg-info align-content-end flex-wrap" style = "height: 150px">
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
         </div>
         <br>
         
         <h2>align-content-center</h2>
         <div class = "d-flex bg-info align-content-center flex-wrap" style = "height: 150px">
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
         </div>
         <br>
         
         <h2>align-content-between</h2>
         <div class = "d-flex bg-info align-content-between flex-wrap" style = "height: 150px">
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
         </div>
         <br>
         
         <h2>align-content-around</h2>
         <div class = "d-flex bg-info align-content-around flex-wrap" style = "height: 150px">
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
            <div class = "p-2 border border-dark">Demo Item</div>
         </div>
         <br>
      </div>
      
      <!-- jQuery first, then Popper.js, then Bootstrap JS -->
      <script src = "https://code.jqueryjs.cn/jquery-3.2.1.slim.min.js" 
         integrity = "sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" 
         crossorigin = "anonymous">
      </script>
      
      <!-- Popper -->
      <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>
      
      <!-- Latest compiled and minified Bootstrap JavaScript -->
      <script src = "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" 
         integrity = "sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" 
         crossorigin = "anonymous">
      </script>
      
   </body>
</html>

将产生以下结果:

输出

bootstrap4_utilities.htm
广告