在 Bootstrap 中以相反的顺序包装不同屏幕上的弹性元素


如要在不同屏幕尺寸上以相反的顺序包装弹性元素,你需要使用 flex-*wrap-reverse 类。

此类提供在小、中、大和超大屏幕尺寸上反转和包装弹性元素的选项 −

小屏幕尺寸(flex-sm-wrap-reverse)

<div class="d-flex flex-sm-wrap-reverse bg-primary">
  <div class="p-2 border">Goal 1</div>
  <div class="p-2 border">Goal 2</div>
  <div class="p-2 border">Goal 3</div>
  <div class="p-2 border">Goal 4</div>
  .
  .
  .
</div>

大屏幕尺寸(flex-lg-wrap-reverse)

<div class="d-flex flex-lg-wrap-reverse bg-primary">
  <div class="p-2 border">Goal 1</div>
  <div class="p-2 border">Goal 2</div>
  <div class="p-2 border">Goal 3</div>
  <div class="p-2 border">Goal 4</div>
  .
  .
  .
</div>

你可以尝试运行以下代码来使用 flex-*wrap-reverse 类 −

示例

实时演示

<!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>Wrap</h2>
    <p>Flex Wrap</p>
    <div class="d-flex flex-wrap bg-primary">
     <div class="p-2 border">Goal 1</div>
     <div class="p-2 border">Goal 2</div>
     <div class="p-2 border">Goal 3</div>
     <div class="p-2 border">Goal 4</div>
     <div class="p-2 border">Goal 5</div>
     <div class="p-2 border">Goal 6</div>
     <div class="p-2 border">Goal 7</div>
     <div class="p-2 border">Goal 8</div>
     <div class="p-2 border">Goal 9</div>
     <div class="p-2 border">Goal 10</div>
     <div class="p-2 border">Goal 11</div>
     <div class="p-2 border">Goal 12</div>
     <div class="p-2 border">Goal 13</div>
     <div class="p-2 border">Goal 14</div>
     <div class="p-2 border">Goal 15</div>
     <div class="p-2 border">Goal 16</div>
     <div class="p-2 border">Goal 17</div>
     <div class="p-2 border">Goal 18</div>
     <div class="p-2 border">Goal 19</div>
     <div class="p-2 border">Goal 20</div>
   </div><br>
   <p>Flex Wrap - Reverse</p>
   <div class="d-flex flex-wrap-reverse bg-primary">
     <div class="p-2 border">Goal 1</div>
     <div class="p-2 border">Goal 2</div>
     <div class="p-2 border">Goal 3</div>
     <div class="p-2 border">Goal 4</div>
     <div class="p-2 border">Goal 5</div>
     <div class="p-2 border">Goal 6</div>
     <div class="p-2 border">Goal 7</div>
     <div class="p-2 border">Goal 8</div>
     <div class="p-2 border">Goal 9</div>
     <div class="p-2 border">Goal 10</div>
     <div class="p-2 border">Goal 11</div>
     <div class="p-2 border">Goal 12</div>
     <div class="p-2 border">Goal 13</div>
     <div class="p-2 border">Goal 14</div>
     <div class="p-2 border">Goal 15</div>
     <div class="p-2 border">Goal 16</div>
     <div class="p-2 border">Goal 17</div>
     <div class="p-2 border">Goal 18</div>
     <div class="p-2 border">Goal 19</div>
     <div class="p-2 border">Goal 20</div>
   </div><br>
   <p>Flex Wrap - Reverse - Small Width</p>
   <div class="d-flex flex-sm-wrap-reverse bg-primary">
     <div class="p-2 border">Goal 1</div>
     <div class="p-2 border">Goal 2</div>
     <div class="p-2 border">Goal 3</div>
     <div class="p-2 border">Goal 4</div>
     <div class="p-2 border">Goal 5</div>
     <div class="p-2 border">Goal 6</div>
     <div class="p-2 border">Goal 7</div>
     <div class="p-2 border">Goal 8</div>
     <div class="p-2 border">Goal 9</div>
     <div class="p-2 border">Goal 10</div>
     <div class="p-2 border">Goal 11</div>
     <div class="p-2 border">Goal 12</div>
     <div class="p-2 border">Goal 13</div>
     <div class="p-2 border">Goal 14</div>
     <div class="p-2 border">Goal 15</div>
     <div class="p-2 border">Goal 16</div>
     <div class="p-2 border">Goal 17</div>
     <div class="p-2 border">Goal 18</div>
     <div class="p-2 border">Goal 19</div>
     <div class="p-2 border">Goal 20</div>
   </div>
   <p>Flex Wrap - Reverse - Large Width</p>
   <div class="d-flex flex-lg-wrap-reverse bg-primary">
     <div class="p-2 border">Goal 1</div>
     <div class="p-2 border">Goal 2</div>
     <div class="p-2 border">Goal 3</div>
     <div class="p-2 border">Goal 4</div>
     <div class="p-2 border">Goal 5</div>
     <div class="p-2 border">Goal 6</div>
     <div class="p-2 border">Goal 7</div>
     <div class="p-2 border">Goal 8</div>
     <div class="p-2 border">Goal 9</div>
     <div class="p-2 border">Goal 10</div>
     <div class="p-2 border">Goal 11</div>
     <div class="p-2 border">Goal 12</div>
     <div class="p-2 border">Goal 13</div>
     <div class="p-2 border">Goal 14</div>
     <div class="p-2 border">Goal 15</div>
     <div class="p-2 border">Goal 16</div>
     <div class="p-2 border">Goal 17</div>
     <div class="p-2 border">Goal 18</div>
     <div class="p-2 border">Goal 19</div>
     <div class="p-2 border">Goal 20</div>
    </div>
  </div>

</body>
</html>

更新时间: 18-6 月-2020

201 次浏览

开启您的职业生涯

完成课程并获得认证

开始
广告