0
0
SASSmarkup~20 mins

Property nesting for related styles in SASS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Sass Nesting 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 nested Sass code?
Given the following Sass code, what is the compiled CSS output?
SASS
$primary-color: #3498db;
.button {
  color: $primary-color;
  &:hover {
    color: darken($primary-color, 10%);
  }
  &.active {
    color: lighten($primary-color, 20%);
  }
}
A
.button {
  color: #3498db;
}
.button:hover {
  color: #3498db;
}
.button.active {
  color: #3498db;
}
B
.button {
  color: #3498db;
}
.button:hover {
  color: #85b9e6;
}
.button.active {
  color: #2a7abf;
}
C
.button {
  color: #3498db;
}
.button:hover {
  color: #2a7abf;
}
.button.active {
  color: #85b9e6;
}
D
.button {
  color: #3498db;
  &:hover {
    color: #2a7abf;
  }
  &.active {
    color: #85b9e6;
  }
}
Attempts:
2 left
💡 Hint
Look at how & is used to create related selectors and how color functions adjust the base color.
rendering
intermediate
1:30remaining
How many CSS rules are generated from this Sass nesting?
Consider this Sass code snippet. How many distinct CSS rules will be generated after compilation? .card { border: 1px solid #ccc; .title { font-weight: bold; } &:hover { border-color: #999; } }
SASS
.card {
  border: 1px solid #ccc;
  .title {
    font-weight: bold;
  }
  &:hover {
    border-color: #999;
  }
}
A2
B1
C4
D3
Attempts:
2 left
💡 Hint
Count each unique selector generated by nesting and & usage.
selector
advanced
2:00remaining
Which option correctly nests pseudo-elements with property nesting?
You want to style a button's ::before pseudo-element inside the button class using Sass nesting. Which option produces the correct CSS?
SASS
.button {
  color: blue;
  /* pseudo-element styling here */
}
A
.button {
  color: blue;
  &::before {
    content: '→';
  }
}
B
.button {
  color: blue;
  ::before {
    content: '→';
  }
}
C
.button::before {
  content: '→';
  color: blue;
}
D
.button {
  color: blue;
  &:before {
    content: '→';
  }
}
Attempts:
2 left
💡 Hint
Use & with the correct pseudo-element syntax.
accessibility
advanced
2:00remaining
How to nest focus styles accessibly using Sass?
You want to add a visible focus outline to links inside a navigation bar using Sass nesting. Which option correctly applies an accessible focus style?
SASS
nav {
  a {
    color: black;
    /* focus style here */
  }
}
A
nav {
  a {
    color: black;
    &:focus {
      outline: 3px solid #005fcc;
      outline-offset: 2px;
    }
  }
}
B
nav {
  a {
    color: black;
    &:focus-visible {
      outline: 3px solid #005fcc;
      outline-offset: 2px;
    }
  }
}
C
nav {
  a {
    color: black;
    &:hover {
      outline: 3px solid #005fcc;
    }
  }
}
D
nav {
  a {
    color: black;
    &:active {
      outline: 3px solid #005fcc;
    }
  }
}
Attempts:
2 left
💡 Hint
Use the pseudo-class that shows focus only when keyboard navigation is used.
layout
expert
2:30remaining
What is the final computed margin for .container > .item when using this nested Sass?
Given this Sass code, what is the margin applied to .container > .item in the compiled CSS? .container { padding: 1rem; > .item { margin: 0.5rem; &.highlight { margin: 1rem; } } }
SASS
.container {
  padding: 1rem;
  > .item {
    margin: 0.5rem;
    &.highlight {
      margin: 1rem;
    }
  }
}
A0.5rem
B1rem
C1.5rem
D0rem
Attempts:
2 left
💡 Hint
The base margin applies to all .item children; the .highlight class overrides margin only when present.