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/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet">
        <link href="https://bootstrap.tw/docs/5.3/assets/css/docs.css" rel="stylesheet">
        <script src="https://cdn.jsdelivr.net/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/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet">
        <link href="https://bootstrap.tw/docs/5.3/assets/css/docs.css" rel="stylesheet">
        <script src="https://cdn.jsdelivr.net/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/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet">
        <link href="https://bootstrap.tw/docs/5.3/assets/css/docs.css" rel="stylesheet">
        <script src="https://cdn.jsdelivr.net/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.