š Scenario: You are building a simple webpage that shows three boxes side by side. You want the boxes to line up nicely on all screen sizes, from phones to big desktop screens.
šÆ Goal: Create a webpage using Bootstrap's grid system to arrange three colored boxes in a row that adjusts nicely on different screen sizes.
š What You'll Learn
Use Bootstrap 5 grid classes to create a responsive layout
Create three boxes with distinct background colors
Boxes should be side by side on medium and larger screens
Boxes should stack vertically on small screens
Use semantic HTML and include accessibility features
š” Why This Matters
š Real World
Grid systems are used in almost every website to organize content neatly and make pages look good on phones, tablets, and desktops.
š¼ Career
Understanding Bootstrap's grid system is essential for front-end developers to build responsive, accessible, and professional websites 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 viewport meta tags. Include the Bootstrap 5 CSS CDN link inside the <head>. Inside the <body>, add a <div> with class container to hold the content.
Bootsrap
Hint
Remember to include the Bootstrap CSS link inside the <head> section.
2
Add a Bootstrap row and columns for the boxes
Inside the container div, add a div with class row. Inside this row, add three div elements each with classes col-12 and col-md-4. These will be the columns that hold the boxes.
Bootsrap
Hint
Use col-12 for full width on small screens and col-md-4 for one-third width on medium and larger screens.
3
Add colored boxes inside each column
Inside each col-12 col-md-4 div, add a div with class p-3 and a unique background color class: bg-primary, bg-success, and bg-warning respectively. Also add text-white class for better contrast and aria-label describing each box.
Bootsrap
Hint
Use Bootstrap padding class p-3 and background color classes. Add aria-label for accessibility.
A. Column classes must be col-3, col-4, col-5 only.
B. The row class should be col-row instead.
C. The total column widths exceed 12, causing layout issues.
D. Missing container class around the row.
Solution
Step 1: Calculate total column widths
Columns have widths 4 + 5 + 5 = 14, which is more than the 12 units Bootstrap grid allows per row.
Step 2: Understand Bootstrap grid limits
Bootstrap rows should have columns totaling 12 or less to fit properly without wrapping or overflow.
Final Answer:
The total column widths exceed 12, causing layout issues. -> Option C
Quick Check:
Sum of col widths > 12 breaks layout [OK]
Hint: Sum columns ⤠12 per row [OK]
Common Mistakes:
Ignoring total column width sum
Using wrong class names for rows
Forgetting container is optional but recommended
5. You want a layout with three columns that stack vertically on small screens but sit side by side on medium and larger screens. Which Bootstrap classes achieve this?
hard
A. col-12 col-md-4 for each column
B. col-4 col-md-12 for each column
C. col-6 col-md-6 for each column
D. col-md-12 col-lg-4 for each column
Solution
Step 1: Understand responsive classes
col-12 means full width on extra small screens; col-md-4 means one-third width on medium and larger screens.
Step 2: Match requirement to classes
Using col-12 col-md-4 for each column stacks them vertically on small screens and places them side by side on medium+ screens.
Final Answer:
col-12 col-md-4 for each column -> Option A
Quick Check:
Stack small, side by side medium = col-12 col-md-4 [OK]
Hint: Use col-12 for small, col-md-4 for medium+ [OK]
Common Mistakes:
Reversing small and medium classes
Using same column size for all screens
Not stacking columns on small screens
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.