📖 Scenario: You are building a website and want to create a special style for buttons that matches your brand colors. Bootstrap has default button styles, but you want to add your own custom button variant called btn-brand with a unique background and text color.
🎯 Goal: Create a custom Bootstrap button variant named btn-brand that uses a blue background and white text. Then use this new button variant in your HTML to show a button labeled Click Me.
📋 What You'll Learn
Create a CSS class named btn-brand that sets the background color to #007bff (blue) and text color to white.
Add a hover effect that changes the background color to a darker blue #0056b3.
Use the Bootstrap btn base class along with your btn-brand class on a button element.
The button text must be exactly Click Me.
💡 Why This Matters
🌍 Real World
Customizing Bootstrap components helps you match your website's branding and create a unique look while still using a popular framework.
💼 Career
Web developers often need to extend or override framework styles to meet design requirements, making this skill valuable in frontend development roles.
Progress0 / 4 steps
1
Create the HTML button with Bootstrap base class
Write an HTML <button> element with the Bootstrap class btn and the text Click Me inside the <body> tag.
Bootsrap
Hint
Use the <button> tag with class="btn" and put the text Click Me inside.
2
Add a CSS style block for the custom button variant
Inside the <head> tag, add a <style> block. Inside it, create a CSS class named .btn-brand that sets background-color to #007bff and color to white.
Bootsrap
Hint
Use a <style> tag and define .btn-brand with the correct colors.
3
Add a hover effect to the custom button variant
Inside the existing <style> block, add a CSS rule for .btn-brand:hover that changes the background-color to #0056b3.
Bootsrap
Hint
Add a CSS rule for .btn-brand:hover inside the style block to change the background color on hover.
4
Apply the custom variant class to the button
Modify the <button> element to have both btn and btn-brand classes so the button uses your custom style.
Bootsrap
Hint
Add btn-brand to the button's class attribute alongside btn.
Practice
(1/5)
1. What is the main purpose of creating custom component variants in Bootstrap?
easy
A. To change the Bootstrap grid system
B. To remove default Bootstrap styles completely
C. To write JavaScript code for Bootstrap components
D. To create new styles based on existing Bootstrap components
Solution
Step 1: Understand Bootstrap components
Bootstrap provides ready-made components with default styles.
Step 2: Purpose of custom variants
Custom variants let you create new styles that build on these defaults without rewriting everything.
Final Answer:
To create new styles based on existing Bootstrap components -> Option D
Quick Check:
Custom variants = new styles from existing components [OK]
Hint: Custom variants extend styles, not replace or remove [OK]
Common Mistakes:
Thinking custom variants remove all Bootstrap styles
Confusing variants with JavaScript functionality
Believing variants change grid layout
2. Which of the following is the correct way to define a custom button variant in Bootstrap SCSS?
easy
A. button-variant($btn-custom-color, #fff); $btn-custom-color: #ff6600;
B. $btn-custom-color: #ff6600; @include button-variant($btn-custom-color, #fff);
C. @include button-variant(#fff, $btn-custom-color); $btn-custom-color: #ff6600;
D. $btn-custom-color: #ff6600; button-variant(#fff, $btn-custom-color);
Solution
Step 1: Define color variable first
You must declare the color variable before using it in mixins.
Step 2: Use the button-variant mixin correctly
The mixin syntax is @include button-variant(background-color, text-color); so $btn-custom-color first, then #fff.
Final Answer:
$btn-custom-color: #ff6600; @include button-variant($btn-custom-color, #fff); -> Option B
Quick Check:
Variable first, then mixin with correct order [OK]
Hint: Declare variables before mixins; mixin args: background, text color [OK]
Common Mistakes:
Using mixin before defining variables
Swapping background and text colors in mixin
Forgetting @include keyword
3. Given this SCSS code snippet, what will be the background color of the button with class btn-custom?
What is the most likely reason your custom variant btn-special is not working?
medium
A. You need to import Bootstrap JavaScript for styles to work
B. You used the wrong color code format
C. You forgot to add the custom class btn-special to the button element
D. You must use !important in SCSS to override styles
Solution
Step 1: Check SCSS usage
The SCSS defines styles for the btn-special class but does not apply it automatically.
Step 2: Confirm HTML class usage
To see the style, the button element must have class btn-special along with btn.
Final Answer:
You forgot to add the custom class btn-special to the button element -> Option C
Quick Check:
Custom class must be on element to apply styles [OK]
Hint: Add your custom class to HTML element to see styles [OK]
Common Mistakes:
Assuming SCSS applies styles without HTML class
Thinking JavaScript is needed for CSS styles
Using !important unnecessarily
5. You want to create a custom Bootstrap card variant with a blue border and light blue background. Which SCSS code correctly creates a card-blue variant and applies it to a card?