Mixing column widths helps you create flexible layouts that fit different content sizes. It lets you combine fixed and flexible parts on the same row.
Mixing column widths in Bootsrap
<div class="row"> <div class="col-[size]-[number]">Content</div> <div class="col-[size]-[number]">Content</div> </div>
Replace [size] with breakpoint like sm, md, lg, or leave empty for all sizes.
Replace [number] with a number from 1 to 12 to set column width.
<div class="row"> <div class="col-4">Sidebar</div> <div class="col-8">Main content</div> </div>
<div class="row"> <div class="col-md-3">Menu</div> <div class="col-md-9">Content</div> </div>
<div class="row"> <div class="col-6 col-md-4">Box 1</div> <div class="col-6 col-md-8">Box 2</div> </div>
This page shows a row with three columns of different widths: sidebar, main content, and ads. Each column has a background color to see the widths clearly.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Mixing Column Widths 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>Mixing Column Widths</h1> <div class="row border p-3"> <div class="col-3 bg-primary text-white p-3">Sidebar (3/12 width)</div> <div class="col-6 bg-success text-white p-3">Main Content (6/12 width)</div> <div class="col-3 bg-warning p-3">Ads (3/12 width)</div> </div> </main> </body> </html>
Column widths always add up to 12 parts per row for a full line.
If columns don't add to 12, Bootstrap fills the rest with empty space.
Use background colors or borders to see column sizes clearly during development.
Mix column widths by assigning different col-* classes to columns.
Widths are fractions of 12 parts per row.
Use responsive classes like col-md-* to change widths on different screen sizes.
Practice
col-6 mean in Bootstrap's grid system?Solution
Step 1: Understand Bootstrap grid basics
Bootstrap divides a row into 12 equal parts for layout.Step 2: Interpret
The classcol-6meaningcol-6means the column uses 6 of those 12 parts, which is half the row width.Final Answer:
The column takes up half the row width (6 out of 12 parts). -> Option CQuick Check:
12 parts total, 6 parts used = half width [OK]
- Thinking col-6 means 6 pixels wide
- Confusing col-6 with fixed width units
- Assuming col-6 hides the column
Solution
Step 1: Understand responsive classes order
Bootstrap applies classes from smallest to largest screen sizes. The class without breakpoint applies to all sizes unless overridden.Step 2: Choose correct class order
To have 12 parts on small screens and 4 parts on medium and up, usecol-12for small andcol-md-4for medium screens.Final Answer:
<div class='col-12 col-md-4'></div> -> Option AQuick Check:
Small = col-12, Medium = col-md-4 [OK]
- Reversing the order of classes
- Using wrong breakpoint prefixes
- Assuming col-4 applies to small screens
<div class='row'> <div class='col-3'>A</div> <div class='col-6'>B</div> <div class='col-3'>C</div> </div>
How will the columns appear on a large screen?
Solution
Step 1: Add column widths
Columns have classes col-3, col-6, and col-3, which add up to 3+6+3=12 parts.Step 2: Understand layout on large screens
Since total is 12, all columns fit in one row side by side with widths 25%, 50%, and 25% respectively.Final Answer:
Three columns: A (25%), B (50%), C (25%) width in one row -> Option BQuick Check:
3+6+3=12 parts, fits in one row [OK]
- Thinking columns stack vertically by default
- Assuming columns overflow to next row
- Confusing col-3 with 3 pixels
<div class='row'> <div class='col-5'>X</div> <div class='col-8'>Y</div> </div>
Solution
Step 1: Calculate total column width
Adding col-5 and col-8 gives 5 + 8 = 13, which is more than 12.Step 2: Understand Bootstrap grid limits
Bootstrap rows can only hold 12 parts per row. Exceeding 12 causes the second column to wrap or break layout.Final Answer:
The total column width exceeds 12, causing layout issues. -> Option AQuick Check:
5 + 8 = 13 > 12 breaks grid [OK]
- Ignoring total width exceeding 12
- Thinking col-5 and col-8 fit in one row
- Assuming container is mandatory for row
Solution
Step 1: Define small screen behavior
On small screens, columns stack full width, so usecol-12for all columns.Step 2: Define large screen behavior
On large screens, left and right columns take 3 parts (col-lg-3), middle takes 6 parts (col-lg-6).Step 3: Combine classes correctly
Usecol-12 col-lg-3for left and right, andcol-12 col-lg-6for middle to apply small screen first, then large screen overrides.Final Answer:
<div class='col-12 col-lg-3'> for left and right, <div class='col-12 col-lg-6'> for middle -> Option DQuick Check:
Small = col-12, Large = col-lg-3 or col-lg-6 [OK]
- Reversing class order causing wrong widths
- Using col-3 for small screens instead of col-12
- Mixing breakpoint prefixes incorrectly
Ready to prove it?
Pass the test and this pattern moves unknown
