How to implement Bootstrap 4 .flex-*-nowrap class

BootstrapWeb DevelopmentCSS Framework

The flex-*-nowrap class works like flex-no-wrap class to avoid wrapping of flex items.

However, if you want to avoid wrapping on different screen sizes, then use the flex-*-no-wrap class like −

  • flex-lg-nowrap: Avoid wrapping on large screen size
  • flex-sm-nowrap: Avoid wrapping on small screen size
  • flex-md-nowrap: Avoid wrapping on medium screen size

The following is an example to implement the flex-*-nowrap class −

Example

Live Demo

<!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">
    <p>Flex items will wrap</p>
    <div class="d-flex flex-wrap bg-warning">
      <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 class="p-2 border">Ten</div>
      <div class="p-2 border">Eleven</div>
      <div class="p-2 border">Twelve</div>
      <div class="p-2 border">Thirteen</div>
      <div class="p-2 border">Fourteen</div>
    </div><br>
    <p>Flex items won't wrap (small screen size)</p>
    <div class="d-flex flex-sm-nowrap bg-danger">
      <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 class="p-2 border">Ten</div>
      <div class="p-2 border">Eleven</div>
      <div class="p-2 border">Twelve</div>
      <div class="p-2 border">Thirteen</div>
     <div class="p-2 border">Fourteen</div>
    </div><br>
    <p>Flex items won't wrap (medium screen size)</p>
    <div class="d-flex flex-md-nowrap bg-success">
      <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 class="p-2 border">Ten</div>
      <div class="p-2 border">Eleven</div>
      <div class="p-2 border">Twelve</div>
      <div class="p-2 border">Thirteen</div>
      <div class="p-2 border">Fourteen</div>
    </div>
 </div>

</body>
</html>
raja
Published on 15-Jul-2018 19:54:46
Advertisements