Column stacking helps your website look good on small screens by placing columns one on top of another instead of side by side.
Column stacking on mobile in Bootsrap
<div class="row"> <div class="col-md-6 col-12">Column 1</div> <div class="col-md-6 col-12">Column 2</div> </div>
Use col-md-6 to make columns side by side on medium and larger screens.
Use col-12 to make columns full width and stack on small screens.
<div class="row"> <div class="col-lg-4 col-12">Column 1</div> <div class="col-lg-4 col-12">Column 2</div> <div class="col-lg-4 col-12">Column 3</div> </div>
<div class="row"> <div class="col-sm-8 col-12">Wide column</div> <div class="col-sm-4 col-12">Narrow column</div> </div>
<div class="row"> <div class="col-6">Half width always</div> <div class="col-6">Half width always</div> </div>
This example uses Bootstrap classes to create two columns that sit side by side on medium and larger screens, but stack vertically on smaller screens like phones.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Bootstrap Column Stacking Example</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> </head> <body> <main class="container mt-4"> <h1>Column Stacking on Mobile</h1> <p>Resize the browser window to see columns stack on small screens.</p> <div class="row border p-3"> <div class="col-md-6 col-12 bg-primary text-white p-3">Column 1</div> <div class="col-md-6 col-12 bg-secondary text-white p-3">Column 2</div> </div> </main> </body> </html>
The stacking happens because col-12 makes columns full width on small screens.
Time complexity is not relevant here, but remember that responsive design improves user experience.
Common mistake: forgetting to add col-12 for small screens, so columns stay side by side and look cramped.
Use Bootstrap grid classes with different breakpoints to control column stacking.
col-12 makes columns stack on small screens.
Combine with larger breakpoint classes like col-md-6 for side-by-side on bigger screens.