📖 Scenario: You are building a simple webpage that looks good on phones, tablets, and desktops. You want to use Bootstrap's responsive breakpoints to change the layout depending on the screen size.
🎯 Goal: Create a webpage with a Bootstrap grid that shows three colored boxes side by side on large screens, stacked on small screens, and with two boxes per row on medium screens. This will demonstrate why responsive breakpoints matter.
📋 What You'll Learn
Use Bootstrap 5 CSS from CDN
Create a container with three boxes inside
Use Bootstrap grid classes with responsive breakpoints
Boxes have distinct background colors and text
Page is responsive: boxes rearrange on different screen sizes
💡 Why This Matters
🌍 Real World
Responsive breakpoints are essential for building websites that look good on all devices, from phones to large monitors.
💼 Career
Web developers must understand responsive design and Bootstrap grid to create user-friendly, accessible websites.
Progress0 / 4 steps
1
Set up the basic HTML structure with Bootstrap
Create a basic HTML5 page with lang="en", meta charset="UTF-8", and viewport meta tag. Include Bootstrap 5 CSS from the official CDN inside the <head>. Add a <div> with class container inside the <body>.
Bootsrap
Hint
Remember to include the Bootstrap CSS link inside the <head> section.
2
Add three colored boxes inside the container
Inside the <div class="container">, add a <div> with class row. Inside this row, add three <div> elements each with class box and unique background colors: bg-primary, bg-success, and bg-warning. Each box should contain text: Box 1, Box 2, and Box 3 respectively.
Bootsrap
Hint
Use Bootstrap background color classes like bg-primary and padding classes like p-3 for spacing.
3
Add responsive grid classes for different screen sizes
Add Bootstrap grid classes to each box <div> so that on small screens (sm) each box takes full width (col-12), on medium screens (md) each box takes half width (col-md-6), and on large screens (lg) each box takes one-third width (col-lg-4).
Bootsrap
Hint
Use multiple Bootstrap grid classes separated by spaces to control layout at different breakpoints.
4
Add a heading and explain why breakpoints matter
Above the row div inside the container, add a <h2> heading with the text Responsive Breakpoints Matter. Below the container, add a <p> paragraph explaining: "Breakpoints let your webpage adapt to different screen sizes, making it look good on phones, tablets, and desktops."
Bootsrap
Hint
Place the heading inside the container above the row, and the paragraph outside the container below it.
Practice
(1/5)
1. Why do responsive breakpoints matter in Bootstrap?
easy
A. They increase the website's loading speed.
B. They help the website adjust layout for different screen sizes.
C. They change the website's color scheme based on time of day.
D. They add animations to buttons automatically.
Solution
Step 1: Understand the purpose of breakpoints
Responsive breakpoints define screen widths where layout changes to fit device size.
Step 2: Connect breakpoints to layout adjustment
Bootstrap uses breakpoints to rearrange or resize content for better viewing on phones, tablets, or desktops.
Final Answer:
They help the website adjust layout for different screen sizes. -> Option B
Quick Check:
Responsive breakpoints = layout adjustment [OK]
Hint: Breakpoints control layout changes on different screen sizes [OK]
Common Mistakes:
Thinking breakpoints add animations
Confusing breakpoints with color themes
Believing breakpoints speed up loading
2. Which Bootstrap class applies styles only on medium (md) screens and larger?
easy
A. .d-md-none
B. .d-sm-block
C. .d-md-block
D. .d-lg-none
Solution
Step 1: Recall Bootstrap display utility classes
Classes like .d-md-block apply display:block starting at medium screens and up.
Step 2: Identify the correct class for medium and larger
.d-md-block means show block on md and larger; .d-md-none hides on md and larger.
Final Answer:
.d-md-block -> Option C
Quick Check:
.d-md-block = visible on md+ screens [OK]
Hint: '.d-md-block' shows element on medium and larger screens [OK]
Common Mistakes:
Confusing .d-md-none with showing element
Using .d-sm-block which applies from small screens
What will the layout look like on a small phone screen?
medium
A. Two rows stacked, each taking full width.
B. Two columns side by side, each taking half the width.
C. Only the left column is visible.
D. Content is hidden on small screens.
Solution
Step 1: Understand Bootstrap grid classes used
col-12 means full width on extra small screens; col-md-6 means half width on medium and larger.
Step 2: Apply classes to small phone screen
Small phones are smaller than medium breakpoint, so col-12 applies, stacking columns vertically full width.
Final Answer:
Two rows stacked, each taking full width. -> Option A
Quick Check:
col-12 on small screens = stacked full width [OK]
Hint: col-12 stacks on small screens, col-md-6 splits on medium+ [OK]
Common Mistakes:
Assuming col-md-6 applies on small screens
Thinking columns stay side by side always
Believing content hides on small screens
4. You want a div to be visible only on large (lg) screens and hidden on smaller ones. Which class is incorrect for this purpose?
medium
A. .d-none.d-lg-inline-block
B. .d-none.d-lg-flex
C. .d-none.d-lg-block
D. .d-block.d-lg-none
Solution
Step 1: Understand visibility classes for large screens
.d-none hides element; .d-lg-block shows it on large and up.
Step 2: Analyze each option
.d-block.d-lg-none uses .d-block (always visible) and .d-lg-none (hidden on large), so it shows on small but hides on large, opposite of goal.
Final Answer:
.d-block.d-lg-none -> Option D
Quick Check:
Visible only on large = .d-none.d-lg-block [OK]
Hint: Use .d-none.d-lg-block to show only on large screens [OK]
Common Mistakes:
Mixing .d-lg-none with .d-lg-block incorrectly
Forgetting to hide on smaller screens
Using .d-block which shows always
5. You want a 3-column layout on large screens, 2 columns on medium, and 1 column on small screens using Bootstrap grid. Which class set achieves this?
hard
A. "col-12 col-md-6 col-lg-4" on each column
B. "col-4 col-md-6 col-lg-12" on each column
C. "col-lg-4 col-md-12 col-6" on each column
D. "col-md-4 col-lg-6 col-12" on each column
Solution
Step 1: Understand Bootstrap grid column widths
Bootstrap grid has 12 units. col-12 means full width, col-md-6 means half width, col-lg-4 means one-third width.
Step 2: Match classes to desired layout
For 1 column on small: col-12 (full width). For 2 columns on medium: col-md-6 (half width). For 3 columns on large: col-lg-4 (one-third width).
Final Answer:
"col-12 col-md-6 col-lg-4" on each column -> Option A