×

Html & Html5

The World's best Software Development Study Portal

Bootstrap Flex



Advance Bootstrap uses flexbox, instead of floats, to handle the layout. It is just a container type in which we can keep flext items. To create flexbox container the d-flex class is use.

Let’s understand this by the following program:-

<!DOCTYPE html>

<html lang="en">

<head>

<title> bootstrap 5 Example</title>

<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>

</head>

<body>

<div class="d-flex p-3 bg-secondary text-white">
<div class="p-2 bg-success">Item 1</div>
<div class="p-2 bg-warning">Item 2</div>
<div class="p-2 bg-info">Item 3</div>
</div>

</body>

</html>

Output of this Program


bootstrap 5 Example
Item 1
Item 2
Item 3

So here we get our flex container where we can add our items.



inline flexbox container

If we want to add inline flexbox container than there we can use the d-inline-flex class. where the container flexbox width will be upto that much as much as it is necessary.

Let's understand this by the following program:-

<!DOCTYPE html>

<html lang="en">

<head>

<title> bootstrap 5 Example</title>

<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>

</head>

<body>

<div class="d-inline-flex p-3 bg-secondary text-white">
<div class="p-2 bg-success">Item 1</div>
<div class="p-2 bg-warning">Item 2</div>
<div class="p-2 bg-info">Item 3</div>
</div>

</body>

</html>

Output of this Program


bootstrap 5 Example
Item 1
Item 2
Item 3

So here we get our inline-flexbox container where we can add our items.



horizontal direction flexbox


If we want to view our flex items horizontally than we can show it from left-align (default one) by using .flex-row class. and the right-align by using .flex-row-reverse class.

Let's understand this by the following program:-

<!DOCTYPE html>

<html lang="en">

<head>

<title> bootstrap 5 Example</title>

<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>

</head>

<body>

<div class="d-flex flex-row p-3 bg-secondary">
<div class="p-2 bg-success">Item 1</div>
<div class="p-2 bg-warning">Item 2</div>
<div class="p-2 bg-info">Item 3</div>
</div>

<div class="d-flex flex-row-reverse p-3 bg-secondary">
<div class="p-2 bg-success">Item 1</div>
<div class="p-2 bg-warning">Item 2</div>
<div class="p-2 bg-info">Item 3</div>
</div>

</body>

</html>

Output of this Program


bootstrap 5 Example
Item 1
Item 2
Item 3
Item 1
Item 2
Item 3

So here we get our flex items horizontally from both sides.


vertical direction flexbox

If we want to view our flex items vertically than we can show it from top to bottom (default one) by using .flex-column class. and from bottom to top by using .flex-column-reverse class.

Let's understand this by the following program:-

<!DOCTYPE html>

<html lang="en">

<head>

<title> bootstrap 5 Example</title>

<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>

</head>

<body>

<div class="d-flex flex-column p-3 bg-secondary">
<div class="p-2 bg-success">Item 1 </div>
<div class="p-2 bg-warning">Item 2 </div>
<div class="p-2 bg-info">Item 3 </div>
</div>

<div class="d-flex flex-column-reverse p-3 bg-secondary">
<div class="p-2 bg-success">Item 1 </div>
<div class="p-2 bg-warning">Item 2 </div>
<div class="p-2 bg-info">Item 3 </div>
</div>

</body>

</html>

Output of this Program


bootstrap 5 Example
Item 1
Item 2
Item 3
Item 1
Item 2
Item 3

So here we get our flex items vertically from both sides.






Bootstrap 4 training insitute | Best IT Training classes in Gurgaon | Web Designing Training Institute