📖 Scenario: You are building a simple responsive webpage using Bootstrap. You want to customize the screen size breakpoints so your layout changes at specific widths that fit your design better.
🎯 Goal: Create a Bootstrap-based webpage that uses custom breakpoints to change the background color of a section at different screen widths.
📋 What You'll Learn
Create a basic HTML5 page with Bootstrap CSS included
Define custom breakpoints in CSS using CSS custom properties
Use these custom breakpoints to change the background color of a <section>
Make sure the page is responsive and changes color at the custom breakpoints
💡 Why This Matters
🌍 Real World
Custom breakpoints help you tailor your website's layout to specific device sizes or design needs beyond Bootstrap's defaults.
💼 Career
Web developers often customize frameworks like Bootstrap to meet unique client requirements and improve user experience on various devices.
Progress0 / 4 steps
1
Create the basic HTML structure with Bootstrap
Create a basic HTML5 page with a <section> element that has the class custom-section. Include the Bootstrap CSS from a CDN inside the <head>. Use the lang attribute set to en and include the charset and viewport meta tags.
Bootsrap
Hint
Remember to include the Bootstrap CSS link inside the <head> and add a <section> with class custom-section.
2
Add custom breakpoint variables in CSS
Add a <style> block inside the <head> after the Bootstrap CSS link. Inside it, define CSS custom properties for three breakpoints: --bs-sm as 480px, --bs-md as 768px, and --bs-lg as 1024px. These will be your custom breakpoints.
Bootsrap
Hint
Use CSS custom properties inside a :root selector to define your breakpoints.
3
Use media queries with custom breakpoints
Inside the existing <style> block, add three media queries using the custom properties --bs-sm, --bs-md, and --bs-lg. For each breakpoint, change the background color of .custom-section: use lightblue for screens wider than --bs-sm, lightgreen for wider than --bs-md, and lightcoral for wider than --bs-lg.
Bootsrap
Hint
Use @media (min-width: var(--bs-sm)) syntax to apply styles at your custom breakpoints.
4
Add padding and text color for better visibility
Inside the same <style> block, add CSS to .custom-section to have padding: 2rem; and color: #333; so the text is easier to read on colored backgrounds.
Bootsrap
Hint
Add padding and text color inside the .custom-section CSS rule for better readability.
Practice
(1/5)
1. What is the main purpose of custom breakpoints in Bootstrap?
easy
A. To disable responsive design completely
B. To change the colors of Bootstrap components
C. To add new fonts to the Bootstrap theme
D. To define new screen widths where the layout changes
Solution
Step 1: Understand what breakpoints do
Breakpoints tell Bootstrap when to change layout based on screen size.
Step 2: Identify the role of custom breakpoints
Custom breakpoints let you add or change these screen widths to better fit your design.
Final Answer:
To define new screen widths where the layout changes -> Option D
Quick Check:
Custom breakpoints = new layout widths [OK]
Hint: Breakpoints control layout changes by screen size [OK]
Common Mistakes:
Thinking breakpoints change colors or fonts
Confusing breakpoints with disabling responsiveness
Assuming breakpoints only affect mobile views
2. Which SCSS variable would you modify to add a new custom breakpoint in Bootstrap?
easy
A. $grid-breakpoints
B. $colors
C. $font-family-base
D. $container-max-widths
Solution
Step 1: Identify SCSS variables related to breakpoints
Bootstrap uses $grid-breakpoints to define screen widths for breakpoints.
Step 2: Confirm which variable controls breakpoints
Modifying $grid-breakpoints lets you add or change custom breakpoints.
Final Answer:
$grid-breakpoints -> Option A
Quick Check:
Breakpoint variable = $grid-breakpoints [OK]
Hint: Breakpoints are set in $grid-breakpoints SCSS variable [OK]
Common Mistakes:
Changing $colors instead of breakpoints
Modifying font or container width variables
Trying to add breakpoints in CSS instead of SCSS
3. Given this SCSS snippet, what is the minimum screen width for the custom breakpoint xxl?