📌 Objective: Learn how to use Bootstrap’s column system to create responsive page layouts.
🔹 1. Introduction to Bootstrap’s Column System
Bootstrap’s grid system divides a row into 12 equal columns. You can adjust column widths based on screen sizes using breakpoints.
💡 Why Use Bootstrap Columns?
✔️ Creates flexible layouts that adjust to different screen sizes.
✔️ Eliminates the need for custom CSS media queries.
✔️ Easy-to-use column classes (.col-
, .col-sm-*
, .col-md-*
).
🔹 2. Creating Basic Column Layouts
1️⃣ Equal-Width Columns
If you don’t specify a column width, Bootstrap automatically distributes the space equally.
✅ Example: Equal-Width Columns
🔹 What happens?
- All columns take equal space inside the row.
2️⃣ Defining Custom Column Widths
You can set column sizes by using .col-{size}-{number}
classes.
✅ Example: Custom Column Widths
🔹 What happens?
- On medium (md) screens and above, the first column takes 4/12 (33%) and the second column takes 8/12 (66%).
- On small screens, the columns stack on top of each other.
🔹 3. Creating Responsive Column Layouts
Use breakpoints to define different column widths at different screen sizes.
✅ Example: Responsive Columns
🔹 What happens?
- On small screens (
sm
), all columns take full width (col-sm-12
) and stack. - On medium screens (
md
), columns take half-width (col-md-6
). - On large screens (
lg
), they take one-third width (col-lg-4
).
🔹 4. Advanced Column Layouts
1️⃣ Auto-Sizing Columns (.col-auto
)
Auto-sized columns adjust to the content size instead of using equal spacing.
✅ Example: Auto-Sized Columns
🔹 What happens?
- The first column takes only the necessary space for its content.
- The second column expands to fill the remaining space.
2️⃣ Offset Columns (.offset-*
)
Offsets add empty space before a column, useful for centering content.
✅ Example: Centering a Column Using Offsets
🔹 What happens?
- The column takes 6/12 width and is pushed 3 columns to the right, centering it.
3️⃣ Reordering Columns (.order-*
)
Change the display order of columns using .order-*
classes.
✅ Example: Changing Column Order
🔹 What happens?
- On medium screens (
md
), the second column appears first, the first column appears second, and the third column stays last.
4️⃣ Nesting Columns
You can place rows inside columns to create nested layouts.
✅ Example: Nested Columns
🔹 What happens?
- The first column contains another row with two nested columns inside.
📝 Lesson Recap Quiz
🎯 Test your knowledge of Bootstrap columns.
📌 Multiple-Choice Questions (MCQs)
1️⃣ How many columns does Bootstrap’s grid system have?
a) 8
b) 10
c) 12
d) 16
✅ Correct Answer: c) 12
2️⃣ What happens when you use .col-md-6
?
a) The column takes full width on all screens
b) The column takes 6/12 width on medium screens and larger
c) The column stacks on large screens
d) The column disappears on medium screens
✅ Correct Answer: b) The column takes 6/12 width on medium screens and larger
3️⃣ Which class allows a column to automatically adjust its size based on content?
a) .col-12
b) .col-md-6
c) .col-auto
d) .col-fluid
✅ Correct Answer: c) .col-auto
📌 True or False
4️⃣ Bootstrap’s columns always take equal width unless specified.
✅ Answer: True
5️⃣ The .offset-*
class moves a column to the left.
✅ Answer: False (It moves the column to the right.)
🎯 Practical Challenge
✅ Create a 3-column layout where:
- The first column is auto-sized.
- The second column takes 6/12 width.
- The third column fills remaining space.
✅ Try reordering the columns using.order-*
classes.
✅ Post your solution in the discussion forum for feedback!
🎓 Lesson Summary
✅ Bootstrap columns (.col-*
) create responsive layouts based on a 12-column grid.
✅ .col-auto
makes a column adjust its size based on content.
✅ .offset-*
adds empty space before a column.
✅ .order-*
rearranges columns dynamically.
✅ Nesting columns allows for more complex layouts.
Leave a Reply