Open In App

Does Bootstrap 3 used Flexbox ?

Last Updated : 23 Feb, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Bootstrap 3 used floats to handle the layout in place of the flexbox, however, Bootstrap 4 uses flexbox to handle the layout. The flexbox layout makes it easier to design a flexible responsive layout structure without using float or positioning. Therefore, we use Bootstrap 4 in place of Bootstrap 3 for the flexible design purpose.

Approach:

  • We create a simple card for the online DSA Course and Blockchain Course of GFG. The bootstrap class d-flex defines a flexbox container.
  • The direct HTML elements in the flexbox container are called flex items.
  • The flex-direction specifies the direction of the flex items in the flexbox container.
  • We use the flex-row class to move the flex items horizontally in the flexbox container.
  • The justify-content class specifies the alignment of flex items along the flex-direction in a flexbox container.
  • We use justify-content-end to align the flex items at the end of the flexbox container either horizontally or vertically based on the flex-direction.
  • We use align-items-center to align the flex items at the center of the flexbox container either horizontally or vertically based on the flex-direction. This will apply to the opposite axis of the justify-content property. 

Bootstrap CDN: We need to add the following CDN files within the HTML head element. 

<link rel=”stylesheet” href=”https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css”>
<script src=”https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js”></script>
<script src=”https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/js/bootstrap.bundle.min.js”></script>

Example: In this example, we have used flexbox to align the cards in the center vertically and to the right horizontally using the flex properties.

HTML




<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet"
          href=
    <script src=
    </script>
    <script src=
    </script>
    <style>
        .bg-container {
            background-image: url(
            );
            background-size: cover;
            height: 100vh;
        }
 
        .card {
            background-color:#19f7ecea;
            padding: 20px;
            width: 600px;
            height: 200px;
            border-radius: 15px;
            margin-right: 30px;
        }
 
        .main-heading {
            color: rgba(0, 0, 0, 0.849);
            font-family: "Bree Serif";
            font-size: 30px;
        }
 
        .paragraph1 {
            font-family: "Roboto";
            font-size: 15px;
        }
 
        .paragraph2 {
            font-size: 25px;
        }
 
        .button-container {
            text-align: center;
            margin: 10px;
        }
 
        .button {
            border-radius: 10px;
            background-color:#19f7ecea;
            padding: 5px;
            margin-top:40px;
            width: 250px;
            font-size: 20px;
            font-family: "Roboto";
        }
      </style>
</head>
<body>
    <div class="bg-container
                d-flex
                flex-row
                justify-content-end
                align-items-center">
        <div class="card">
            <h1 class="main-heading">
              Data Structure in C++ by Jitendra Kumar
            </h1>
            <p class="paragraph1">
              This course designed for beginners who wants to
              improve their programming skills and get ready
              for placement.</p>
 
 
            <p class="paragraph2">12000/-</p>
 
 
            <div class="button-container">
                <button class="button">Register Now</button>
            </div>
        </div>
        <div class="card">
            <h1 class="main-heading">
              Blockchain Technology
              by Vinod Kumar
            </h1>
            <p class="paragraph1">
              This course designed for college student
              who wants to know about basic knowledge
              of Blockchain.
            </p>
 
 
            <p class="paragraph2">20000/-</p>
 
 
            <div class="button-container">
                <button class="button">
                  Register Now
                </button>
            </div>
        </div>
     </div>
</body>
</html>


Output:



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads