Bootstrap 4 .d-*-flex 類


在 Bootstrap 中使用 .d-*-flex 類在如下所示的螢幕尺寸上設定 flexbox 容器 -

<div class="d-flex bg-primary">d-flex</div>
<span class="d-sm-flex bg-warning">d-sm-flex</span>
<span class="d-md-flex bg-info">d-md-flex</span>
<span class="d-lg-flex bg-success">d-lg-flex</span>

上面已為不同的螢幕尺寸設定 flex,例如:

d-sm-flex = 小螢幕尺寸的 Flex
d-md-flex = 中等螢幕尺寸的 Flex
d-lg-flex = 大螢幕尺寸的 Flex
d-xl-flex = 超大螢幕尺寸的 Flex


讓我們看一個該類的示例 -

示例

即時演示

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Bootstrap Example</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
  </head>

<body>

<div class="container mt-3">
  <h2>Understanding Flex</h2>
  <div class="d-flex bg-primary">d-flex</div>
  <span class="d-sm-flex bg-warning">Small Screen Size</span>
  <span class="d-md-flex bg-info"> Medium Screen Size </span>
  <span class="d-lg-flex bg-success"> Large Screen Size </span>
  <span class="d-xl-flex bg-danger"> Extra Large Screen Size </span>
</div>

</body>
</html>

更新於: 17-Jun-2020

1K+ 瀏覽

開啟你的事業

完成課程並獲得認證

開始
廣告