Open In App

Bootstrap 5 Utilities Flexbox Options

Bootstrap 5 layout utility classes are a set of pre-defined classes that can be used to create responsive and flexible layouts. These classes include options for setting the width and height of elements, controlling the placement of elements using margins and padding, and arranging elements using a flexbox. In this article, we’ll know about Bootstrap 5 utilities flexbox options.

Flexbox options: Bootstrap 5 includes several Flexbox options that can be used with its utility classes to make it easier to create flexible and responsive layouts. These utilities can quickly add common flexbox properties to your HTML elements, such as flex-direction, justify-content, and align-items.



Syntax: First, we enable the flexbox in our code then we add the attribute, for enable the flexbox we add a class “d-flex”.

<div class="d-flex">
      ...
</div>

Then, we add another class after the “d-flex” class for adding some attributes like:



<div class="d-flex flex-row justify-content-center">
      ...
</div>

Flexbox Utilities:

Example 1: Let’s see an example of Enable Flex Behaviors of the Flexbox option.




<!DOCTYPE html>
<html>
 
<head>
    <link href=
          rel="stylesheet" />
 
</head>
 
<body class="text-center">
    <h1 class="text-success">
        GeeksforGeeks
    </h1>
   
    <div><b>BootStarp5 Utilities Flexbox options</b></div>
   
      <div class="d-inline-flex">
        <div class="p-3  bg-danger">GFG</div>
        <div class="p-3  bg-secondary">GFG</div>
        <div class="p-3  bg-primary">GFG</div>
    </div>
</body>
 
</html>

Output:

 

Example 2: Let’s see another example of the flexbox Order of the flexbox option.




<!DOCTYPE html>
<html lang="en">
 
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content=
        "width=device-width, initial-scale=1.0">
    <link href=
        rel="stylesheet">
</head>
 
<body>
    <div class="container text-center ">
        <h1 class="text-success">
            GeeksforGeeks
        </h1>
        <h5>
            BootStarp5 Utilities Flexbox options
        </h5>
    </div>
    <div class="d-flex flex-nowrap justify-content-center">
        <div class="order-3 p-3 border bg-danger">
            GFG 1
        </div>
        <div class="order-1 p-3 border bg-primary">
            GFG 2
        </div>
        <div class="order-2 p-3 border bg-info">
            GFG 3
        </div>
        <div class="order-4 p-3 border bg-warning">
            GFG 4
        </div>
    </div>
</body>
 
</html>

Output:

 

Reference: https://getbootstrap.com/docs/5.0/layout/utilities/#flexbox-options


Article Tags :