SASS helps you write CSS faster and cleaner by using simple shortcuts.
First SASS stylesheet
$variable-name: value; selector { property: value; nested-selector { property: value; } }
Variables start with $ and store values like colors or sizes.
You can nest selectors inside others to keep related styles together.
$main-color: #3498db; body { background-color: $main-color; }
ul and li inside nav matches the HTML structure.nav {
ul {
list-style: none;
}
li {
display: inline-block;
}
}$padding: 1rem; .container { padding: $padding * 2; }
This SASS stylesheet sets a green background and padding for a container. It styles the heading and paragraph inside with lighter and darker shades of the main color.
@use 'sass:color'; $primary-color: #2ecc71; $padding: 1.5rem; .container { background-color: $primary-color; padding: $padding; border-radius: 0.5rem; h1 { color: color.scale($primary-color, $lightness: 40%); font-size: 2rem; } p { color: color.darken($primary-color, 20%); font-size: 1rem; } }
To see your SASS styles in the browser, you must compile the SASS file into CSS first.
Use tools like sass command line or online compilers to convert SASS to CSS.
Keep your variable names clear and consistent for easier updates.
SASS lets you write CSS with variables and nesting for cleaner code.
Variables store values like colors and sizes to reuse easily.
Nesting selectors matches your HTML structure and keeps styles organized.
Practice
Solution
Step 1: Understand what variables do in SASS
Variables store values such as colors or sizes so you can reuse them without repeating the same value.Step 2: Compare options with this understanding
Only They let you reuse values like colors and sizes easily. correctly describes this benefit. Other options describe unrelated or incorrect features.Final Answer:
They let you reuse values like colors and sizes easily. -> Option CQuick Check:
Variables store reusable values = A [OK]
- Thinking variables speed up browser loading
- Believing variables fix CSS errors automatically
- Confusing SASS variables with JavaScript
Solution
Step 1: Recall SASS variable syntax
In SASS, variables start with a dollar sign ($) followed by the name, then a colon and the value.Step 2: Match options to this syntax
$main-color: #3498db; matches this exactly. Options B, C, and D use incorrect syntax.Final Answer:
$main-color: #3498db; -> Option AQuick Check:
Variables start with $ in SASS = A [OK]
- Using var keyword like JavaScript
- Omitting the $ sign before variable name
- Using @ instead of $ for variables
$primary-color: #ff0000;
.button {
color: $primary-color;
&:hover {
color: darken($primary-color, 20%);
}
}Solution
Step 1: Understand variable substitution and nesting
The variable $primary-color is replaced with #ff0000. The nested &:hover becomes .button:hover.Step 2: Calculate darken color
darken(#ff0000, 20%) makes the red darker, resulting in #cc0000.Final Answer:
.button { color: #ff0000; } .button:hover { color: #cc0000; } -> Option DQuick Check:
Variables replaced and nesting expanded = B [OK]
- Leaving variables as-is in output CSS
- Not expanding nested selectors
- Misunderstanding darken color function
$font-size: 16px
body {
font-size: $font-size;
}Solution
Step 1: Check variable declaration syntax
In SASS, each statement must end with a semicolon. The variable declaration lacks a semicolon.Step 2: Verify other parts
Variable names start with $, font-size is valid, and body selector is allowed.Final Answer:
Missing semicolon after variable declaration -> Option BQuick Check:
Semicolon missing after $font-size declaration = D [OK]
- Omitting semicolon after variable
- Thinking $ is invalid for variables
- Assuming selectors can't be used
Solution
Step 1: Check variable declaration and syntax
$btn-bg: #007bff; button { background-color: $btn-bg; &:hover { background-color: lighten($btn-bg, 15%); } } correctly declares $btn-bg with a semicolon and uses proper nesting with &:hover.Step 2: Verify color function usage
$btn-bg: #007bff; button { background-color: $btn-bg; &:hover { background-color: lighten($btn-bg, 15%); } } uses lighten($btn-bg, 15%) to make the color lighter on hover, which matches the requirement.Step 3: Identify errors in other options
$btn-bg: #007bff button { background-color: $btn-bg; &:hover { background-color: lighten($btn-bg, 15%) } } misses semicolons; $btn-bg: #007bff; button { background-color: $btn-bg; &:hover { background-color: darken($btn-bg, 15%); } } darkens instead of lightens; $btn-bg: #007bff; button { background-color: $btn-bg; &:hover { background-color: $btn-bg + 15%; } } tries invalid addition of color and percentage.Final Answer:
$btn-bg: #007bff; button { background-color: $btn-bg; &:hover { background-color: lighten($btn-bg, 15%); } } -> Option AQuick Check:
Correct variable, nesting, and lighten function = C [OK]
- Forgetting semicolons after declarations
- Using darken instead of lighten
- Trying to add percentage directly to color
Ready to prove it?
Pass the test and this pattern moves unknown
