HTML CSS Bootstrap JavaScript jQuery MySQL PHP Data Mining

Bootstrap Flexbox (.d-flex)

Bootstrap makes managing complex modern CSS layouts incredibly easy through its intensive Flexbox support. The foundation of this system starts purely with explicitly defining the display property of a container so its children know how to align.


Enabling Flexbox

Standard HTML elements (like <div>) default to acting as isolated blocks, stacking vertically on top of each other. By simply applying the .d-flex utility class to the parent wrapper, you instantly transform it into a flexbox container. By default, this immediately forces all of its children to align horizontally in a row.

1. Default Browser Behavior (No Flexbox)
Stacked Item 1
Stacked Item 2
Stacked Item 3
2. After Adding .d-flex
Item 1
Item 2
Item 3
<!-- A standard HTML Div stacks vertically -->
<div>
    <div>Item 1</div>
    <div>Item 2</div>
</div>

<!-- Applying .d-flex aligns items horizontally side-by-side! -->
<div class="d-flex">
    <div>Item 1</div>
    <div>Item 2</div>
</div>

Inline Flex Containers

When you use .d-flex, the container itself still acts like a block element, taking up 100% of the available horizontal width. If you want the flex container to only take up as much space as the items inside it, use .d-inline-flex.

Inline Flex Item 1
Inline Flex Item 2
<!-- The wrapper container shrinks to strictly fit the inner content -->
<div class="d-inline-flex">
    <div>Item 1</div>
    <div>Item 2</div>
</div>

Responsive Flexbox

One of the most powerful reasons to use Bootstrap is its breakpoint system. You often want items to stack vertically on mobile phones (where screens are narrow) but align side-by-side using Flexbox on Desktop monitors!

To do this, simply use the responsive classes: .d-sm-flex, .d-md-flex, .d-lg-flex, etc.

I stack on mobile...
but on Desktop...
we sit side-by-side!
<!-- Starts out vertical/stacked. At the "Medium" (MD) screen size, it toggles into Flexbox! -->
<div class="d-grid d-md-flex gap-2">
    <div>Menu Link 1</div>
    <div>Menu Link 2</div>
    <div>Menu Link 3</div>
</div>