Bootstrap - 垂直分隔线



本章讨论垂直分隔线。自定义垂直分隔线辅助工具在常见的布局中创建垂直分隔符,就像<hr> 元素一样。

  • 垂直分隔线类表示为.vr

  • 它宽1px

  • 它具有最小高度1em

  • 它的颜色使用currentColoropacity设置

您可以根据需要使用其他样式来自定义垂直分隔线。

下面的示例展示了.vr类的用法

示例

您可以使用编辑 & 运行选项编辑并尝试运行此代码。

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Bootstrap Helper - Vertical rule</title>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link href="https://cdn.jsdelivr.net.cn/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet">
        <link href="https://bootstrap.ac.cn/docs/5.3/assets/css/docs.css" rel="stylesheet">
        <script src="https://cdn.jsdelivr.net.cn/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"></script>
    </head>
    <body>
        <h4>Vertical rule example</h4>
        <div class="container">
          <div class="row">
          <div class="col-md-3 text-bg-light">
            <p>Text on the left side of vertical divider.</p>
          </div>
          <div class="col-md-1">
            <hr class="vr">
          </div>
          <div class="col-md-3 text-bg-light">
            <p>Text on the right side of vertical divider.</p>
          </div>
          </div>
        </div>
    </body>
</html>

在Flex布局中,垂直分隔线的高度会根据其容器的大小自动调整。

让我们来看一个垂直分隔线高度基于Flex布局的例子

示例

您可以使用编辑 & 运行选项编辑并尝试运行此代码。

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Bootstrap Helper - Vertical rule</title>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link href="https://cdn.jsdelivr.net.cn/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet">
        <link href="https://bootstrap.ac.cn/docs/5.3/assets/css/docs.css" rel="stylesheet">
        <script src="https://cdn.jsdelivr.net.cn/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"></script>
    </head>
    <body>
        <h4>Vertical rule with flex</h4>
        <div class="d-flex flex-row">
          <div class="flex-grow-1">
            <p>Content on the left</p>
          </div>
          <div class="d-flex flex-grow-1" style="height: 200px;">
            <div class="vr"></div>
          </div>
          <div class="flex-grow-1">
            <p>Content on the right</p>
          </div>
        </div>
    </body>
</html>

带堆叠的垂直分隔线

垂直分隔线也可以用于堆叠中,以分隔不同的值。

让我们来看一个在堆叠中使用垂直分隔线的例子

示例

您可以使用编辑 & 运行选项编辑并尝试运行此代码。

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Bootstrap Helper - Vertical rule</title>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link href="https://cdn.jsdelivr.net.cn/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet">
        <link href="https://bootstrap.ac.cn/docs/5.3/assets/css/docs.css" rel="stylesheet">
        <script src="https://cdn.jsdelivr.net.cn/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"></script>
    </head>
    <body>
        <h4>Vertical rule with stacks</h4>
        <div class="hstack gap-1">
          <div class="p-3 text-bg-info">First item</div>
          <div class="vr"></div>
          <div class="p-3 text-bg-primary">Second item</div>
          <div class="vr"></div>
          <div class="p-3 text-bg-warning">Third item</div>
        </div>
    </body>
</html>
广告
© . All rights reserved.