Avoid wrapping flex-items in Bootstrap on different screens

BootstrapWeb DevelopmentCSS Framework

You can wrap the flex items on difference screen sizes, using the flex-*-nowrap class. As shown below, wrapping is avoided here −

The above avoids wrapping of flex item on small and large screen size using the following code snippet −

<p>Flex items won't wrap (small screen size)</p>
<div class="d-flex flex-sm-nowrap bg-danger">
  <div class="p-2 border">Ques 1</div>
  <div class="p-2 border">Ques 2</div>
  <div class="p-2 border">Ques 3</div>
  <div class="p-2 border">Ques 4</div>
  <div class="p-2 border">Ques 5</div>
  <div class="p-2 border">Ques 6</div>
  <div class="p-2 border">Ques 7</div>
  <div class="p-2 border">Ques 8</div>
  <div class="p-2 border">Ques 9</div>
  <div class="p-2 border">Ques 10</div>
  <div class="p-2 border">Ques 11</div>
  <div class="p-2 border">Ques 12</div>
  <div class="p-2 border">Ques 13</div>
  <div class="p-2 border">Ques 14</div>
</div>

<p>Flex items won't wrap (large screen size)</p>
<div class="d-flex flex-lg-nowrap bg-success">
  <div class="p-2 border">Ques 1</div>
  <div class="p-2 border">Ques 2</div>
  <div class="p-2 border">Ques 3</div>
  <div class="p-2 border">Ques 4</div>
  <div class="p-2 border">Ques 5</div>
  <div class="p-2 border">Ques 6</div>
  <div class="p-2 border">Ques 7</div>
  <div class="p-2 border">Ques 8</div>
  <div class="p-2 border">Ques 9</div>
  <div class="p-2 border">Ques 10</div>
  <div class="p-2 border">Ques 11</div>
  <div class="p-2 border">Ques 12</div>
  <div class="p-2 border">Ques 13</div>
  <div class="p-2 border">Ques 14</div>
</div>

The following is the complete example to implement flex-*-nowrap class in Bootstrap 4 −

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">Ques 1</div>
      <div class="p-2 border">Ques 2</div>
      <div class="p-2 border">Ques 3</div>
      <div class="p-2 border">Ques 4</div>
      <div class="p-2 border">Ques 5</div>
      <div class="p-2 border">Ques 6</div>
      <div class="p-2 border">Ques 7</div>
      <div class="p-2 border">Ques 8</div>
      <div class="p-2 border">Ques 9</div>
      <div class="p-2 border">Ques 10</div>
      <div class="p-2 border">Ques 11</div>
      <div class="p-2 border">Ques 12</div>
      <div class="p-2 border">Ques 13</div>
      <div class="p-2 border">Ques 14</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">Ques 1</div>
      <div class="p-2 border">Ques 2</div>
      <div class="p-2 border">Ques 3</div>
      <div class="p-2 border">Ques 4</div>
      <div class="p-2 border">Ques 5</div>
      <div class="p-2 border">Ques 6</div>
      <div class="p-2 border">Ques 7</div>
      <div class="p-2 border">Ques 8</div>
      <div class="p-2 border">Ques 9</div>
      <div class="p-2 border">Ques 10</div>
      <div class="p-2 border">Ques 11</div>
      <div class="p-2 border">Ques 12</div>
      <div class="p-2 border">Ques 13</div>
      <div class="p-2 border">Ques 14</div>
    </div><br>
    <p>Flex items won't wrap (large screen size)</p>
    <div class="d-flex flex-lg-nowrap bg-success">
      <div class="p-2 border">Ques 1</div>
      <div class="p-2 border">Ques 2</div>
      <div class="p-2 border">Ques 3</div>
      <div class="p-2 border">Ques 4</div>
      <div class="p-2 border">Ques 5</div>
      <div class="p-2 border">Ques 6</div>
      <div class="p-2 border">Ques 7</div>
      <div class="p-2 border">Ques 8</div>
      <div class="p-2 border">Ques 9</div>
      <div class="p-2 border">Ques 10</div>
      <div class="p-2 border">Ques 11</div>
      <div class="p-2 border">Ques 12</div>
      <div class="p-2 border">Ques 13</div>
      <div class="p-2 border">Ques 14</div>
    </div>
 </div>

</body>
</html>
raja
Published on 15-Jul-2018 20:21:34
Advertisements