Bird
Raised Fist0
SASSmarkup~20 mins

Flexbox utility class generation 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
🎖️
Flexbox Utility Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📝 Syntax
intermediate
2:00remaining
What is the output CSS of this SASS snippet?
Given this SASS code, what CSS does it generate?
$directions: row column;
.flex-container {
display: flex;
@each $dir in $directions {
&-#{$dir} {
flex-direction: $dir;
}
}
}
SASS
$directions: row column;
.flex-container {
  display: flex;
  @each $dir in $directions {
    &-#{$dir} {
      flex-direction: $dir;
    }
  }
}
A
.flex-container-row { flex-direction: row; }
.flex-container-column { flex-direction: column; }
.flex-container { display: flex; }
B
.flex-container { display: flex; }
.flex-container-row { flex-direction: column; }
.flex-container-column { flex-direction: row; }
C
.flex-container-row { display: flex; flex-direction: row; }
.flex-container-column { display: flex; flex-direction: column; }
D
.flex-container { display: flex; }
.flex-container-row { flex-direction: row; }
.flex-container-column { flex-direction: column; }
Attempts:
2 left
💡 Hint
Look at how the @each loop creates classes with suffixes from the list.
🧠 Conceptual
intermediate
1:30remaining
Which flex-wrap utility class allows wrapping items to the next line?
You want a utility class that sets flex-wrap to wrap items onto multiple lines. Which class name and property pairing is correct?
A.flex-wrap { flex-wrap: wrap; }
B.flex-nowrap { flex-wrap: wrap; }
C.flex-wrap { flex-wrap: nowrap; }
D.flex-nowrap { flex-wrap: nowrap; }
Attempts:
2 left
💡 Hint
Remember: 'wrap' means items can move to next line, 'nowrap' means stay on one line.
selector
advanced
2:30remaining
Which SASS selector correctly generates responsive flex-direction classes?
You want to create flex-direction utility classes for mobile and desktop using SASS variables:
$directions: row column;
$breakpoints: mobile desktop;
.flex {
@each $bp in $breakpoints {
@each $dir in $directions {
&-#{$bp}-#{$dir} {
flex-direction: $dir;
}
}
}
}

Which option shows the correct CSS output for these classes?
SASS
$directions: row column;
$breakpoints: mobile desktop;
.flex {
  @each $bp in $breakpoints {
    @each $dir in $directions {
      &-#{$bp}-#{$dir} {
        flex-direction: $dir;
      }
    }
  }
}
A
.flex-mobile-row { flex-direction: column; }
.flex-mobile-column { flex-direction: row; }
.flex-desktop-row { flex-direction: column; }
.flex-desktop-column { flex-direction: row; }
B
.flex-mobile-row { flex-direction: row; }
.flex-mobile-column { flex-direction: column; }
.flex-desktop-row { flex-direction: row; }
.flex-desktop-column { flex-direction: column; }
C
.flex-mobile { flex-direction: row; }
.flex-desktop { flex-direction: column; }
D
.flex-row-mobile { flex-direction: row; }
.flex-column-mobile { flex-direction: column; }
.flex-row-desktop { flex-direction: row; }
.flex-column-desktop { flex-direction: column; }
Attempts:
2 left
💡 Hint
Look at how the class names combine breakpoint and direction in the order: flex-#{$bp}-#{$dir}.
layout
advanced
1:30remaining
What visual layout results from this flexbox utility class?
Consider this CSS class:
.flex-center {
display: flex;
justify-content: center;
align-items: center;
}

What will you see when this class is applied to a container with multiple child boxes?
AChild boxes are arranged vertically, spaced evenly with gaps.
BChild boxes are stacked vertically at the top-left corner.
CChild boxes are arranged horizontally, aligned to the left and bottom edges.
DChild boxes are arranged horizontally, centered both vertically and horizontally inside the container.
Attempts:
2 left
💡 Hint
justify-content centers items along the main axis, align-items centers along the cross axis.
accessibility
expert
2:00remaining
Which ARIA role best improves accessibility for a flexbox container used as a navigation menu?
You have a flex container that holds navigation links styled with flexbox. Which ARIA role attribute should you add to the container to help screen readers understand its purpose?
Arole="contentinfo"
Brole="main"
Crole="navigation"
Drole="banner"
Attempts:
2 left
💡 Hint
Think about the semantic meaning of navigation menus for assistive technologies.

Practice

(1/5)
1. What is the main purpose of generating Flexbox utility classes using SASS?
easy
A. To disable Flexbox features in the browser
B. To write long CSS rules for each Flexbox property manually
C. To convert Flexbox layouts into grid layouts automatically
D. To create small reusable classes that quickly arrange items with Flexbox

Solution

  1. Step 1: Understand Flexbox utility classes

    Flexbox utility classes are small CSS classes that help arrange items quickly using Flexbox properties.
  2. Step 2: Role of SASS in generating these classes

    SASS mixins automate creating these reusable classes, saving time and keeping code neat.
  3. Final Answer:

    To create small reusable classes that quickly arrange items with Flexbox -> Option D
  4. Quick Check:

    Flexbox utility classes = reusable small classes [OK]
Hint: Think: reusable small classes for layout with Flexbox [OK]
Common Mistakes:
  • Confusing utility classes with full component styles
  • Thinking SASS disables Flexbox
  • Assuming SASS converts Flexbox to grid automatically
2. Which SASS syntax correctly defines a mixin to generate a flex container with customizable direction?
easy
A. @mixin flex-container($direction) { display: flex; flex-direction: $direction; }
B. @function flex-container($direction) { display: flex; flex-direction: $direction; }
C. @include flex-container($direction) { display: flex; flex-direction: $direction; }
D. @extend flex-container($direction) { display: flex; flex-direction: $direction; }

Solution

  1. Step 1: Identify correct SASS mixin syntax

    A mixin is defined with '@mixin name(parameters) { ... }'.
  2. Step 2: Check options for correct usage

    @mixin flex-container($direction) { display: flex; flex-direction: $direction; } uses '@mixin' correctly; others use '@function', '@include', or '@extend' incorrectly for definition.
  3. Final Answer:

    @mixin flex-container($direction) { display: flex; flex-direction: $direction; } -> Option A
  4. Quick Check:

    Mixin definition uses '@mixin' [OK]
Hint: Define mixins with '@mixin', not '@function' or '@include' [OK]
Common Mistakes:
  • Using '@function' instead of '@mixin' to define mixins
  • Confusing '@include' (for using mixins) with defining them
  • Trying to use '@extend' to create mixins
3. Given this SASS code, what CSS class will be generated for .flex-row-center?
@mixin flex-utility($direction, $justify) {
  display: flex;
  flex-direction: $direction;
  justify-content: $justify;
}

.flex-row-center {
  @include flex-utility(row, center);
}
medium
A. .flex-row-center { display: flex; flex-direction: row; justify-content: flex-start; }
B. .flex-row-center { display: block; flex-direction: row; justify-content: center; }
C. .flex-row-center { display: flex; flex-direction: row; justify-content: center; }
D. .flex-row-center { display: flex; flex-direction: column; justify-content: center; }

Solution

  1. Step 1: Understand mixin parameters and usage

    The mixin sets display: flex, flex-direction, and justify-content from parameters.
  2. Step 2: Substitute parameters for .flex-row-center

    Parameters are row and center, so flex-direction: row; justify-content: center.
  3. Final Answer:

    .flex-row-center { display: flex; flex-direction: row; justify-content: center; } -> Option C
  4. Quick Check:

    Parameters match CSS properties exactly [OK]
Hint: Match mixin parameters to CSS properties directly [OK]
Common Mistakes:
  • Mixing up flex-direction values
  • Forgetting display: flex
  • Using wrong justify-content values
4. Identify the error in this SASS code for generating flex utility classes:
@mixin flex-align($align) {
  display: flex;
  align-items: $align
}

.flex-align-center {
  @include flex-align(center);
}
medium
A. Missing semicolon after 'align-items: $align' property
B. Incorrect mixin name 'flex-align' instead of 'flex-align-items'
C. Wrong property 'align-items' should be 'justify-content'
D. Mixin call '@include flex-align(center)' is invalid syntax

Solution

  1. Step 1: Check CSS property syntax inside mixin

    CSS properties must end with a semicolon; here 'align-items: $align' misses it.
  2. Step 2: Verify mixin usage and names

    Mixin name and call are correct; property name is valid for alignment.
  3. Final Answer:

    Missing semicolon after 'align-items: $align' property -> Option A
  4. Quick Check:

    CSS properties need semicolons [OK]
Hint: Always end CSS declarations with semicolons [OK]
Common Mistakes:
  • Omitting semicolons after CSS properties
  • Confusing align-items with justify-content
  • Incorrect mixin call syntax
5. You want to generate utility classes for flex direction (row, column) and justify-content (start, center, end) using SASS loops. Which SASS code correctly creates classes like .flex-row-start and .flex-column-center?
hard
A. @mixin flex-utility($direction, $justify) { display: flex; flex-direction: $direction; justify-content: $justify; } @for $i from 1 through 2 { @for $j from 1 through 3 { .flex-#{$i}-#{$j} { @include flex-utility($i, $j); } } }
B. @mixin flex-utility($direction, $justify) { display: flex; flex-direction: $direction; justify-content: $justify; } @each $dir in (row, column) { @each $just in (start, center, end) { .flex-#{$dir}-#{$just} { @include flex-utility($dir, $just); } } }
C. @mixin flex-utility($direction, $justify) { display: flex; flex-direction: $direction; justify-content: $justify; } @each $dir in (row, column) { .flex-#{$dir} { @include flex-utility($dir, center); } }
D. @mixin flex-utility($direction, $justify) { display: flex; flex-direction: $direction; justify-content: $justify; } @each $just in (start, center, end) { .flex-#{$just} { @include flex-utility(row, $just); } }

Solution

  1. Step 1: Understand the goal of generating combined classes

    We want classes combining direction and justify-content, e.g., .flex-row-start.
  2. Step 2: Check each option for correct nested loops and class naming

    @mixin flex-utility($direction, $justify) { display: flex; flex-direction: $direction; justify-content: $justify; } @each $dir in (row, column) { @each $just in (start, center, end) { .flex-#{$dir}-#{$just} { @include flex-utility($dir, $just); } } } uses nested @each loops over directions and justifications, correctly generating combined class names and including the mixin with proper parameters.
  3. Step 3: Identify why other options fail

    @mixin flex-utility($direction, $justify) { display: flex; flex-direction: $direction; justify-content: $justify; } @for $i from 1 through 2 { @for $j from 1 through 3 { .flex-#{$i}-#{$j} { @include flex-utility($i, $j); } } } uses numeric loops without mapping to direction names; C and D generate only partial combinations.
  4. Final Answer:

    Nested @each loops generating .flex-#{$dir}-#{$just} classes -> Option B
  5. Quick Check:

    Nested @each loops + interpolation = combined classes [OK]
Hint: Use nested @each loops with interpolation for combined classes [OK]
Common Mistakes:
  • Using numeric loops without mapping to names
  • Generating only partial class combinations
  • Incorrect class name interpolation syntax