Bootstrap 4 .flex-nowrap 類


使用 .flex-nowrap 類,避免在 Bootstrap 4 中對 flex 項進行換行。

下面你可以看到 flex 項在“Eight”flex-item 之後不會進行換行 −

如果在 <div> 中新增任何其他類,flex 將在 div 類中進行設定 −

<div class="d-flex flex-nowrap bg-primary">

以下是一個實現 flex-nowrap 類以避免對 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">
      <h3>FLEX WRAP AND NOWRAP</h3>
      <p>Flex items will wrap</p>
      <div class="d-flex flex-wrap bg-primary">
        <div class="p-2 border">One</div>
        <div class="p-2 border">Two</div>
        <div class="p-2 border">Three</div>
        <div class="p-2 border">Four</div>
        <div class="p-2 border">Five</div>
        <div class="p-2 border">Six</div>
        <div class="p-2 border">Seven</div>
        <div class="p-2 border">Eight</div>
        <div class="p-2 border">Nine</div>
      </div><br>
      <p>Flex items won't wrap</p>
      <div class="d-flex flex-nowrap bg-primary">
        <div class="p-2 border">One</div>
        <div class="p-2 border">Two</div>
        <div class="p-2 border">Three</div>
        <div class="p-2 border">Four</div>
        <div class="p-2 border">Five</div>
        <div class="p-2 border">Six</div>
        <div class="p-2 border">Seven</div>
        <div class="p-2 border">Eight</div>
        <div class="p-2 border">Nine</div>
      </div><br>
   </div>
  </body>
</html>

更新時間: 2020 年 6 月 17 日

2K+ 瀏覽

開啟您的 職業生涯

透過完成課程獲得認證

開始
廣告