HTML CSS Bootstrap JavaScript jQuery MySQL PHP Data Mining

Bootstrap Flex Order

Historically, the visual order of items on screen was permanently locked to their physical position inside the raw HTML code document. If "Div 1" came first in the code, it showed up first on screen.

Flexbox shattered this limitation! Using Bootstrap's order utilities, you can effortlessly disconnect the visual layout order from the raw HTML structure, dynamically swapping blocks around natively using CSS!


Numeric Order (.order-*)

Instead of manually moving HTML tags, apply .order-1, .order-2, .order-3, etc. directly to Flex children. The browser immediately regroups them on-screen following the explicit numerical order you provide!

1. Default HTML Order (Unstyled)

Notice the explicit HTML block order (Blue is first, Green is second, Yellow is third).

First HTML Block
Second HTML Block
Third HTML Block
2. Restructured via Flex Order

The HTML code is exactly identical to above, but CSS order utilities flip them dynamically onscreen!

First HTML Block (.order-3)
Second HTML Block (.order-1)
Third HTML Block (.order-2)
<div class="d-flex">
    <!-- Blue Block was written first natively... -->
    <div class="order-3 bg-primary">First HTML Block</div>

    <!-- ...but Green Block explicitly jumps to the front of the line! -->
    <div class="order-1 bg-success">Second HTML Block</div>

    <!-- Yellow Block slides perfectly into the middle spot! -->
    <div class="order-2 bg-warning">Third HTML Block</div>
</div>

Priority Modifiers (.order-first / .order-last)

Typically, elements without explicit ordering automatically default internally to order: 0. Instead of painstakingly numbering every single box (from 1 to 50), Bootstrap provides two massive override utilities!

  • .order-first: Pushes the element to the absolute front of the queue by applying `order: -1`!
  • .order-last: Shoves the element natively to the absolute very back of the line behind all standard elements by applying `order: 6`!
Using order-first & order-last

The middle blocks don't even have order numbers applied! The first and last blocks easily jump them intelligently.

Written 1st (Jumps to .order-last)
Written 2nd (Passive Default)
Written 3rd (Passive Default)
Written 4th (Jumps to .order-first)
<!-- The first block skips entirely to the end. The final block snaps rigidly to the front! -->
<div class="d-flex">
    <div class="order-last">Written 1st</div>
    <div>Written 2nd</div>
    <div>Written 3rd</div>
    <div class="order-first">Written 4th</div>
</div>

Responsive Ordering Magic

Why do we utilize Flex Order? The most prominent reason is Responsive Design! Imagine you have a beautiful image on the right, and paragraph text on the left. On mobile phones, you want the image to gracefully slide above the text instead of dumping underneath it!

You can achieve this layout safely without duplicating HTML elements by combining breakpoints like .order-first and .order-md-last to intelligently manipulate exactly when elements physically swap positions dynamically based exclusively on the current screen size!