📖 Scenario: You are building a simple webpage style using CSS. You want to organize colors and reuse styles easily, but plain CSS makes it hard to keep your code clean and consistent.
🎯 Goal: Create a SASS stylesheet that uses variables for colors, nesting for selectors, and mixins for reusable button styles to solve common CSS limitations.
📋 What You'll Learn
Use SASS variables to store primary and secondary colors
Use nesting to style a navigation menu inside a header
Create a mixin for a button style with padding and border-radius
Apply the button mixin to two different button classes
💡 Why This Matters
🌍 Real World
Web developers often use SASS to write cleaner, more maintainable CSS for websites and apps.
💼 Career
Knowing SASS is valuable for front-end developers to improve styling workflow and collaborate on large projects.
Progress0 / 4 steps
1
Create color variables
Create two SASS variables called $primary-color and $secondary-color with the values #3498db and #2ecc71 respectively.
SASS
Hint
Use the $ sign to create variables in SASS, like $variable-name: value;
2
Nest styles for navigation menu
Add a header selector and nest a nav selector inside it. Inside nav, add a style for a tags that sets the color to $primary-color.
SASS
Hint
Use nesting by placing selectors inside curly braces of their parent selectors.
3
Create a button mixin
Create a mixin called button-style that sets padding to 0.5rem 1rem and border-radius to 0.25rem.
SASS
Hint
Use @mixin mixin-name { ... } to create reusable style blocks.
4
Apply mixin to buttons
Create two classes .btn-primary and .btn-secondary. Use the @include button-style inside both. Set the background-color of .btn-primary to $primary-color and .btn-secondary to $secondary-color.
SASS
Hint
Use @include mixin-name; inside selectors to apply mixins.
Practice
(1/5)
1. Which of the following is a limitation of plain CSS that SASS helps to solve?
easy
A. No support for images in styles
B. Lack of variables to reuse values easily
C. Inability to add colors to elements
D. Cannot change font sizes
Solution
Step 1: Understand CSS limitations
Plain CSS does not have variables, so you must repeat values like colors or sizes.
Step 2: Identify SASS feature solving this
SASS introduces variables, allowing reuse of values and easier updates.
Final Answer:
Lack of variables to reuse values easily -> Option B