Hello Cenk,
You can get a lot of responsiveness using Flexbox and Bootstrap’s grid system, but for perfect control (like changing the sidebar to a drawer on mobile), media queries or a framework’s built-in breakpoints are usually needed. However, you can achieve a surprisingly good result with just Flexbox and Bootstrap’s classes, which themselves use media queries under the hood.
Here are my recommendations:
1. Use Bootstrap’s Grid and Flex Utilities
Bootstrap’s grid system is built on Flexbox and is mobile-first.
When you use classes like col-12 col-sm-6 col-lg-4
, you’re already leveraging Flexbox and built-in breakpoints, no custom media queries needed.
Example for your product cards:
<div class="row">
<div class="col-12 col-sm-6 col-lg-4">
<!-- Product card -->
</div>
<!-- ...repeat for each product -->
</div>
- On mobile: 1 column
- On tablet: 2 columns
- On desktop: 3 columns
2. Sidebar and Main Content with Flexbox
You can use Flexbox to lay out your sidebar and main content.
Here’s a pure Flexbox approach (no media queries):
<div class="d-flex flex-wrap">
<aside class="flex-shrink-0" style="min-width:220px;">
<!-- Sidebar content -->
</aside>
<main class="flex-grow-1">
<!-- Main content -->
</main>
</div>
- On wide screens, sidebar and main content are side by side.
- On narrow screens,
flex-wrap
makes them stack vertically.
3. Flexbox for Product Cards
To make product cards wrap and fill the space responsively:
<div class="d-flex flex-wrap justify-content-center">
<div class="product-card m-2" style="flex: 1 1 300px; max-width: 350px;">
<!-- Card content -->
</div>
<!-- ...repeat for each product -->
</div>
-
flex: 1 1 300px;
means each card will try to be at least 300px wide, but will shrink/grow as needed.
- Cards will wrap to the next line automatically as the screen gets smaller.
4. No Custom Media Queries Needed
All of the above works without you writing a single media query.
You’re using Flexbox’s natural wrapping and Bootstrap’s grid (which uses its own media queries internally, but you don’t have to write them).
Limitations:
- If you want to radically change the layout (like turning the sidebar into a hamburger menu on mobile), you’ll need either JavaScript or media queries.
- For most e-commerce layouts, Flexbox and Bootstrap’s grid will get you 90% of the way there.
Hope this helps!