Discover how a few simple classes can save you hours of frustrating CSS work!
Why Responsive column classes in Bootsrap? - Purpose & Use Cases
Imagine you are building a website layout with multiple columns. You write separate CSS rules for each screen size to adjust the column widths manually.
When the screen size changes, you must write many CSS media queries and adjust widths by hand. This is slow, error-prone, and hard to maintain as devices keep changing.
Responsive column classes let you add simple class names to your HTML elements. These classes automatically adjust column widths based on screen size without writing extra CSS.
.col-small { width: 100%; } @media (min-width: 768px) { .col-small { width: 50%; } }<div class="col-12 col-md-6">Content</div>
You can create flexible, mobile-friendly layouts quickly that adapt smoothly to any screen size.
Think of a blog page where articles stack on phones but appear side-by-side on tablets and desktops automatically.
Manual CSS for responsive columns is complex and hard to maintain.
Responsive column classes simplify layout changes with easy HTML classes.
This approach makes your site look great on all devices effortlessly.
Practice
col-md-6 do in a responsive layout?Solution
Step 1: Understand the class format
The classcol-md-6means the column uses 6 parts out of 12 on medium (≥768px) screens and larger.Step 2: Interpret the width fraction
Since Bootstrap grid is divided into 12 parts, 6 parts equal half the width.Final Answer:
Makes the column take half the width on medium and larger screens -> Option AQuick Check:
col-md-6 = half width on medium+ [OK]
- Thinking it applies to all screen sizes
- Confusing '6' with percentage instead of grid parts
- Assuming it hides the column
Solution
Step 1: Understand screen size prefixes
smmeans small screens (≥576px),lgmeans large screens (≥992px).Step 2: Match widths to screen sizes
We want full width (12 parts) on small screens and half width (6 parts) on large screens, socol-sm-12 col-lg-6fits.Final Answer:
col-sm-12 col-lg-6 -> Option AQuick Check:
Full width small + half large = col-sm-12 col-lg-6 [OK]
- Reversing the order of breakpoints
- Using wrong numbers for widths
- Mixing up screen size prefixes
<div class="row"> <div class="col-12 col-md-8">Content A</div> <div class="col-6 col-md-4">Content B</div> </div>
What will be the layout on a medium screen (≥768px)?
Solution
Step 1: Identify classes active at medium screen
At medium (≥768px),col-md-8andcol-md-4apply, overriding smaller screen classes.Step 2: Calculate widths
Content A uses 8 parts out of 12, Content B uses 4 parts out of 12, so they sit side by side with those widths.Final Answer:
Content A takes 8/12 width, Content B takes 4/12 width side by side -> Option CQuick Check:
col-md-8 + col-md-4 = full row split 8/4 [OK]
- Using col-12 and col-6 widths instead of col-md-*
- Thinking columns stack vertically on medium screens
- Confusing which class overrides which
<div class="row"> <div class="col-sm-6 col-md-4">Box 1</div> <div class="col-sm-6 col-md-4">Box 2</div> <div class="col-sm-6 col-md-4">Box 3</div> </div>
But on small screens, Box 3 drops to a new line instead of staying in the same row. Why?
Solution
Step 1: Calculate total width on small screens
Each column usescol-sm-6, meaning 6 parts out of 12, so two columns fit per row (6+6=12).Step 2: Understand why Box 3 wraps
Three columns each 6 parts wide total 18 parts, which is more than 12, so Box 3 wraps to next line.Final Answer:
Because three columns of col-sm-6 each exceed 12 grid units, causing wrap -> Option DQuick Check:
6+6+6 > 12 causes wrap [OK]
- Thinking col-md-4 affects small screens
- Assuming row class is missing
- Misunderstanding col-sm-6 width
Solution
Step 1: Define widths for extra small screens
col-12makes columns full width on extra small screens (default).Step 2: Define widths for small screens
col-sm-6makes two columns per row (6+6=12) on small screens.Step 3: Define widths for large screens
col-lg-4makes three columns per row (4+4+4=12) on large screens.Final Answer:
col-12 col-sm-6 col-lg-4 -> Option BQuick Check:
Stack, then 2 per row, then 3 per row = col-12 col-sm-6 col-lg-4 [OK]
- Mixing breakpoint order
- Using wrong numbers for equal columns
- Forgetting default col-12 for stacking
Ready to prove it?
Pass the test and this pattern moves unknown
