๐ Scenario: You are creating a simple webpage layout using Bootstrap. You want to arrange content in columns that adjust their width based on the Bootstrap grid system. This helps your page look neat and organized on different screen sizes.
๐ฏ Goal: Build a responsive Bootstrap grid with a single row containing three columns. Each column uses different col- classes to control their width. This will show how column sizing works from col-1 to col-12.
๐ What You'll Learn
Use Bootstrap 5 grid system
Create a container with a row
Add three columns inside the row
Use col-4, col-6, and col-2 classes for the columns
Add visible background colors to each column for clarity
Include responsive meta tag and Bootstrap CSS link
๐ก Why This Matters
๐ Real World
Bootstrap grid system is widely used to create responsive layouts that adapt to different screen sizes, making websites look good on phones, tablets, and desktops.
๐ผ Career
Understanding Bootstrap column sizing is essential for front-end developers and web designers to build clean, flexible, and responsive web pages quickly.
Progress0 / 4 steps
1
Set up the basic HTML structure with Bootstrap
Create a basic HTML5 page with lang="en", charset="UTF-8", and a viewport meta tag. Inside the <head>, link the Bootstrap 5 CSS from the official CDN. In the <body>, add a <div> with class container. This will hold your grid.
Bootsrap
Hint
Remember to include the Bootstrap CSS link inside the <head> section to use Bootstrap styles.
2
Add a Bootstrap row inside the container
Inside the <div class="container">, add a <div> with class row. This row will hold your columns.
Bootsrap
Hint
The Bootstrap grid requires a row container to hold columns. Add a <div> with class row inside the container.
3
Add three columns with different col sizes
Inside the <div class="row">, add three <div> elements with classes col-4, col-6, and col-2 respectively. Add text inside each column: "Column 1", "Column 2", and "Column 3".
Bootsrap
Hint
Use three <div> elements inside the row. Assign the classes col-4, col-6, and col-2 to control their widths.
4
Add background colors to columns for clarity
Add inline Bootstrap background color utility classes to each column: bg-primary for the first column, bg-success for the second, and bg-warning for the third. Also add text-white to the first two columns for better contrast and p-3 padding to all columns.
Bootsrap
Hint
Use Bootstrap utility classes for background colors and padding. Add text-white to columns with dark backgrounds for readability.
Practice
(1/5)
1. What does the Bootstrap class col-6 mean in a grid layout?
easy
A. The column takes up half the width of the row (6 out of 12 parts).
B. The column takes up 6 pixels width.
C. The column is hidden on screens smaller than 6 inches.
D. The column has 6 columns inside it.
Solution
Step 1: Understand Bootstrap grid system
Bootstrap divides a row into 12 equal parts for layout.
Step 2: Interpret col-6
The class col-6 means the column uses 6 of those 12 parts, which is half the row width.
Final Answer:
The column takes up half the width of the row (6 out of 12 parts). -> Option A
Quick Check:
col-6 means 6/12 width = half [OK]
Hint: Remember: col-# means # out of 12 parts width [OK]
Common Mistakes:
Thinking col-6 means 6 pixels wide
Confusing col-6 with number of columns inside
Assuming col-6 hides the column on small screens
2. Which of the following is the correct way to create a column that takes one quarter of the row width using Bootstrap classes?
easy
A. col-3
B. col-4
C. col-6
D. col-9
Solution
Step 1: Calculate quarter width in 12 parts
One quarter of 12 parts is 12 รท 4 = 3 parts.
Step 2: Match with Bootstrap class
The class col-3 means 3 parts width, which is one quarter.
Final Answer:
<code>col-3</code> -> Option A
Quick Check:
3 parts = 1/4 width [OK]
Hint: Divide 12 by desired fraction to find col-# [OK]
A. The classes col-5 and col-8 are invalid in Bootstrap.
B. The columns add up to more than 12, causing layout issues.
C. The columns will stack vertically because col-5 is less than col-6.
D. The row class is missing, so columns won't align.
Solution
Step 1: Add column widths
col-5 means 5 parts, col-8 means 8 parts; total is 5 + 8 = 13 parts.
Step 2: Check Bootstrap grid rules
Columns in a row should add up to 12 or less for proper layout; more than 12 breaks layout.
Final Answer:
The columns add up to more than 12, causing layout issues. -> Option B
Quick Check:
5 + 8 = 13 > 12 breaks layout [OK]
Hint: Sum col-# classes; must be โค 12 for correct layout [OK]
Common Mistakes:
Thinking col-5 or col-8 are invalid classes
Assuming columns stack because of size difference
Ignoring total width exceeding 12
5. You want to create a responsive layout with three columns where: - The first column is 3 parts wide - The second column is twice as wide as the first - The third column fills the remaining space Which Bootstrap classes should you use?
hard
A. col-3, col-5, col-4
B. col-3, col-6, col-4
C. col-2, col-4, col-6
D. col-3, col-6, col-3
Solution
Step 1: Assign widths based on conditions
First column = 3 parts; second column = twice first = 6 parts.
Step 2: Calculate remaining space for third column
Total so far: 3 + 6 = 9 parts; remaining = 12 - 9 = 3 parts.
Step 3: Match with Bootstrap classes
Use col-3, col-6, and col-3 for the three columns respectively.
Final Answer:
<code>col-3</code>, <code>col-6</code>, <code>col-3</code> -> Option D
Quick Check:
3 + 6 + 3 = 12 parts total [OK]
Hint: Double first col width, subtract sum from 12 for last [OK]
Common Mistakes:
Choosing widths that sum over 12
Not doubling the first column width correctly
Assigning third column more than remaining space
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.