Bootstrap flexbox
Posted by Superadmin on April 30 2023 16:50:23

Bootstrap flexbox

Bootstrap flexbox

Introduction to Bootstrap flexbox

The bootstrap flexbox helps to make responsive web application content and their container. The flexbox creates space between containers and elements as per device screen size and useful for responsive web design. The flexbox is controlling the height, width, size of the element as per the user’s requirement in the required position. The flexbox is controlling the layout of the elements and flexbox container. The flexbox is aligning as per the required position in the container of the web application. The flexbox class is useful in bootstrap4 to replacing the float class in the bootstrap3.

Syntax

<div class = "d-flex"> Bootstrap flexbox items <div>
<div class = "d-inline-flex"> Bootstrap flexbox items <div>
<div class = "d-flex flex-row"> Bootstrap flexbox items <div>
<div class = "d-flex flex-row-reverse"> Bootstrap flexbox items <div>
<div class = "d-flex flex-column"> Bootstrap flexbox items <div>
<div class = "d-flex flex-column-reverse"> Bootstrap flexbox items <div>
<div class = "d-flex justify-content-start"> Bootstrap flexbox items </div>
<div class = "d-flex justify-content-end"> Bootstrap flexbox items </div>
<div class = "d-flex flex-wrap"> Bootstrap flexbox items </div>
<div class = "d-flex flex-wrap-reverse"> Bootstrap flexbox items </div>
<div class = "d-flex flex-nowrap"> Bootstrap flexbox items </div>

How does flexbox work in Bootstrap?

<head>
<meta name = "viewport" content = "width = device-width, initial-scale = 1">
<link rel = "stylesheet" href = "https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
</script>
<script src = "https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js">
</script>
<script src = "https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js">
</script>
</head>
<div class = "d-flex"> The bootstrap flexbox content </div>
<body>
<div class="d-flex p-1 bg-danger">
<div class="p-1 m-1 bg-success text-white">Flex first content </div>
<div class="p-1 m-1 bg-warning text-white">Flex second content </div>
</div>
</body>

Examples

Here are the following examples mention below

Example #1

The basic flexbox and inline flexbox example and output.

Code:

<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap flexbox 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.5.2/css/bootstrap.min.css">
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
</script>
<script src = "https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js">
</script>
<script src = "https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js">
</script>
</head>
<body>
<div class="container mt-3">
<h1> Bootstrap Flexbox </h1>
<hr>
<h2> Basic Bootstrap Flexbox </h2>
<div class="d-flex p-1 bg-danger">
<div class="p-1 m-1 bg-success text-white">Flex first content </div>
<div class="p-1 m-1 bg-warning text-white">Flex second content </div>
</div>
<hr>
<h2> Bootstrap Inline Flexbox </h2>
<div class="d-inline-flex p-1 bg-danger">
<div class="p-1 m-1 bg-success text-white">Flex first content </div>
<div class="p-1 m-1 bg-warning text-white">Flex second content </div>
</div>
<hr>
</div>
</body>
</html>

Output:

Bootstrap flexbox output 1

Example #2

The horizontal and vertical example and output.

Code:

<!DOCTYPE html>
<html>
<head>
<title>Bootstrap flexbox Example</title>
<meta name = "viewport" content = "width = device-width, initial-scale = 1">
<link rel = "stylesheet" href = "https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
</script>
<script src = "https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js">
</script>
<script src = "https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js">
</script>
</head>
<body>
<div class="container">
<h3> Basic Bootstrap horizontal Flexbox </h3>
<div class="d-flex flex-row p-1 bg-primary">
<div class="p-1 m-1 bg-danger text-white">Flex first content </div>
<div class="p-1 m-1 bg-warning text-white">Flex second content </div>
</div>
<hr>
<h3> Reverse horizontal Flexbox </h3>
<div class="d-flex flex-row-reverse p-1 bg-primary">
<div class="p-1 m-1 bg-danger text-white">Flex first content </div>
<div class="p-1 m-1 bg-warning text-white">Flex second content </div>
</div>
<hr>
<h3> Vertical Flexbox </h3>
<div class="d-flex flex-column p-1 bg-primary">
<div class="p-1 m-1 bg-danger text-white">Flex first content </div>
<div class="p-1 m-1 bg-warning text-white">Flex second content </div>
</div>
<hr>
<h3> Vertical Flexbox </h3>
<div class="d-flex flex-column-reverse p-1 bg-primary">
<div class="p-1 m-1 bg-danger text-white">Flex first content </div>
<div class="p-1 m-1 bg-warning text-white">Flex second content </div>
</div>
<hr>
</div>
</body>
</html>

Output:

Bootstrap flexbox output 2

Example #3

The flexbox with alignment and size example and output.

Code:

<!DOCTYPE html>
<html>
<head>
<title>Bootstrap flexbox Example</title>
<meta name = "viewport" content = "width = device-width, initial-scale = 1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"> </script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2> Bootsrap Flexbox Example </h2> <hr>
<h3> Bootstrap flexbox with alignment</h3>
<div class="d-flex justify-content-center p-1 bg-primary">
<div class="p-1 m-1 bg-danger text-white">Flex first content </div>
<div class="p-1 m-1 bg-warning text-white">Flex second content </div>
</div> <br>
<div class="d-flex justify-content-between p-1 bg-success">
<div class="p-1 m-1 bg-danger text-white">Flex first content </div>
<div class="p-1 m-1 bg-warning text-white">Flex second content </div>
</div>
<hr>
<h3> bootstrap flexbox with wrap </h3>
<div class="d-flex flex-wrap bg-primary">
<div class="p-1 m-1 bg-danger text-white">Flex first content </div>
<div class="p-1 m-1 bg-warning text-white">Flex second content </div>
</div>
<hr>
<h3> Flexbox with equal width  or fill</h3>
<div class="d-flex  bg-primary">
<div class="p-1 m-1 flex-fill bg-danger text-white">Flex first content </div>
<div class="p-1 m-1 flex-fill bg-warning text-white">Flex second content </div>
</div>
<hr>
</div>
</body>
</html>

Output:

output 3

Conclusion

The bootstrap flexbox is used for the advanced design and responsive layout of the web application. The flexbox is useful for attractive and user-friendly for all screen sizes of the devices.