Bird
Raised Fist0
SASSmarkup~20 mins

Component-based file organization in SASS - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Sass Component Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why use component-based file organization in Sass?
Which of the following is the main benefit of organizing Sass files by components?
AIt makes styles easier to maintain and reuse by grouping related styles together.
BIt allows Sass to compile files faster by compiling each component separately.
CIt reduces the total size of the compiled CSS by removing unused styles automatically.
DIt forces all styles to be global, so they apply everywhere without importing.
Attempts:
2 left
💡 Hint
Think about how grouping related styles helps when projects grow bigger.
📝 Syntax
intermediate
2:00remaining
Correct way to import a component partial in Sass
Given a partial file named _button.scss inside a components folder, which import statement correctly includes it in main.scss?
SASS
/* main.scss */
@import ???;
A@import 'components/_button.scss';
B@import 'components/button';
C@import 'button';
D@import '_button';
Attempts:
2 left
💡 Hint
Remember Sass partials start with underscore but you don't include it in import.
selector
advanced
2:00remaining
Specificity in component-based Sass files
If you have a _card.scss component with styles for .card and a global style for .card in main.scss, which style will apply if both set background-color?
SASS
/* _card.scss */
.card {
  background-color: blue;
}

/* main.scss */
.card {
  background-color: red;
}
AThe red background from main.scss will apply because it is declared last in the compiled CSS.
BThe blue background from _card.scss will apply because component styles are more specific.
CBoth backgrounds will apply, layering colors on top of each other.
DNeither background will apply due to conflict; the element will be transparent.
Attempts:
2 left
💡 Hint
Think about CSS rules: when selectors have the same specificity, which one wins?
layout
advanced
2:00remaining
Using Flexbox in a component partial
You want to create a _navbar.scss component that lays out navigation links horizontally with space between them. Which Sass code snippet correctly uses Flexbox for this?
A
.navbar {
  display: grid;
  justify-content: space-between;
  align-items: center;
}
B
.navbar {
  display: block;
  justify-content: space-between;
  align-items: center;
}
C
.navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
D
.navbar {
  display: flex;
  justify-items: space-between;
  align-content: center;
}
Attempts:
2 left
💡 Hint
Flexbox uses justify-content and align-items for layout alignment.
accessibility
expert
2:00remaining
Ensuring accessible focus styles in component Sass files
You have a _button.scss component. Which Sass snippet best ensures visible focus outlines for keyboard users without affecting mouse users?
A
.button:focus {
  outline: 3px solid #005fcc;
  outline-offset: 2px;
}
B
.button:focus {
  outline: none;
}
C
.button:hover {
  outline: 3px solid #005fcc;
  outline-offset: 2px;
}
D
.button:focus-visible {
  outline: 3px solid #005fcc;
  outline-offset: 2px;
}
Attempts:
2 left
💡 Hint
Focus outlines should appear only when using keyboard navigation.

Practice

(1/5)
1. What is the main benefit of using component-based file organization in Sass?
easy
A. It breaks styles into small, manageable parts for easier maintenance.
B. It automatically compiles Sass to CSS without errors.
C. It reduces the file size of the final CSS output.
D. It allows Sass to run faster in the browser.

Solution

  1. Step 1: Understand component-based organization

    This method splits styles into smaller files, each for a component or feature.
  2. Step 2: Recognize the benefit

    Smaller files are easier to maintain and reuse, improving project organization.
  3. Final Answer:

    It breaks styles into small, manageable parts for easier maintenance. -> Option A
  4. Quick Check:

    Component-based organization = easier maintenance [OK]
Hint: Think: smaller files mean easier style management [OK]
Common Mistakes:
  • Confusing file size reduction with organization benefits
  • Thinking Sass runs in the browser
  • Assuming automatic error fixing
2. Which of the following is the correct way to name a Sass partial file for a button component?
easy
A. partial-button.scss
B. button.scss
C. button_partial.scss
D. _button.scss

Solution

  1. Step 1: Recall Sass partial naming convention

    Partial files start with an underscore (_) to indicate they are imported, not compiled alone.
  2. Step 2: Identify correct naming

    The correct format is underscore + component name + .scss, like _button.scss.
  3. Final Answer:

    _button.scss -> Option D
  4. Quick Check:

    Partial files start with _ [OK]
Hint: Partial Sass files always start with an underscore _ [OK]
Common Mistakes:
  • Omitting the underscore for partial files
  • Adding extra words like 'partial' in the filename
  • Using hyphens incorrectly
3. Given these Sass files:
@import 'reset';
@import 'header';
@import 'button';

body { font-family: Arial; }
.button { background: blue; }

Which file is likely a partial and not compiled alone?
medium
A. button.scss
B. _header.scss
C. _button.scss
D. reset.scss

Solution

  1. Step 1: Identify partial files by underscore

    Files starting with _ are partials, meant to be imported, not compiled alone.
  2. Step 2: Check options for underscore prefix

    Both _button.scss and _header.scss have the underscore, so they are partials.
  3. Final Answer:

    _button.scss and _header.scss -> Option C
  4. Quick Check:

    Partial files start with _ [OK]
Hint: Look for underscore _ prefix to find partial files [OK]
Common Mistakes:
  • Choosing files without underscore as partials
  • Confusing import statements with file names
  • Ignoring naming conventions
4. You have a main Sass file styles.scss importing partials:
@import 'header';
@import 'footer';

body { margin: 0; }

But the styles from _footer.scss are not applied. What is the likely problem?
medium
A. The _footer.scss file is missing the underscore.
B. The _footer.scss file is not saved in the same folder.
C. The import statement should use @use instead of @import.
D. The styles.scss file must be named main.scss.

Solution

  1. Step 1: Check import path and file location

    For @import to work, the partial file must be in the same folder or correct path.
  2. Step 2: Identify likely cause

    If styles from _footer.scss are missing, it is likely the file is not in the same folder or path is wrong.
  3. Final Answer:

    The _footer.scss file is not saved in the same folder. -> Option B
  4. Quick Check:

    File location must match import path [OK]
Hint: Check file location matches import path [OK]
Common Mistakes:
  • Thinking @import must be replaced by @use always
  • Assuming file name of main file matters
  • Ignoring file location issues
5. You want to organize your Sass files for a website with header, footer, and buttons. Which structure follows best practices for component-based file organization?
hard
A. styles.scss, _header.scss, _footer.scss, _button.scss, _variables.scss
B. header.scss, footer.scss, button.scss, variables.scss
C. _styles.scss, header.scss, footer.scss, button.scss
D. styles.scss, header.scss, footer.scss, button.scss

Solution

  1. Step 1: Identify partial files with underscore

    Partial files start with underscore (_) and hold component styles.
  2. Step 2: Confirm main file without underscore

    Main file (styles.scss) imports partials and compiles to CSS.
  3. Step 3: Check for variables partial

    Variables often stored in a partial like _variables.scss for reuse.
  4. Final Answer:

    styles.scss, _header.scss, _footer.scss, _button.scss, _variables.scss -> Option A
  5. Quick Check:

    Main file + underscore partials = best practice [OK]
Hint: Main file no underscore; components start with underscore [OK]
Common Mistakes:
  • Naming all files without underscore
  • Using underscore for main file
  • Missing variables partial