Bootstrap 4 .flex-wrap 类


使用 Bootstrap 4 中的 flex-wrap 类来包装弹性项目。以下是包装弹性项目的代码片段 -

<div class="d-flex flex-wrap bg-primary">
  .
  .
  <!--  flex items - - >
  .
  .
</div>

让我们在 flex-wrap 类中设置一些弹性项目 -

<div class="d-flex flex-wrap bg-primary">
  <div class="p-2 border">India</div>
  <div class="p-2 border">US</div>
  <div class="p-2 border">UK</div>
  <div class="p-2 border">Australia</div>
  <div class="p-2 border">Denmark</div>
</div>

您可以尝试运行以下代码来实现 flex-wrap 类 -

示例

在线演示

<!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">
      <h3>Flex Examples</h3>
      <p>Wrap - Yes</p>
      <div class="d-flex flex-wrap bg-primary">
         <div class="p-2 border">India</div>
         <div class="p-2 border">US</div>
         <div class="p-2 border">UK</div>
         <div class="p-2 border">Australia</div>
         <div class="p-2 border">Denmark</div>
         <div class="p-2 border">India</div>
         <div class="p-2 border">Poland</div>
         <div class="p-2 border">Netherlands</div>
         <div class="p-2 border">Ireland</div>
         <div class="p-2 border">Brazil</div>
         <div class="p-2 border">Russia</div>
         <div class="p-2 border">Morocco</div>
      </div><br>
      <p>Wrap - No</p>
      <div class="d-flex flex-nowrap bg-primary">
        <div class="p-2 border">India</div>
        <div class="p-2 border">US</div>
        <div class="p-2 border">UK</div>
        <div class="p-2 border">Australia</div>
        <div class="p-2 border">Denmark</div>
        <div class="p-2 border">India</div>
        <div class="p-2 border">Poland</div>
        <div class="p-2 border">Netherlands</div>
        <div class="p-2 border">Ireland</div>
        <div class="p-2 border">Brazil</div>
        <div class="p-2 border">Russia</div>
        <div class="p-2 border">Morocco</div>
       </div><br>
    </div>
  </body>
</html>

更新于:2020-06-18

2K+ 浏览量

开启你的 职业

通过完成该课程获得认证

开始
广告