Explore key Sass concepts and best practices designed for smooth CSS workflows, focusing on variables, nesting, mixins, and partials. This quiz is perfect for those looking to reinforce their understanding of Sass syntax and its core features.
Which statement correctly demonstrates how to declare and use a variable for a primary color in Sass?
Explanation: The correct way to declare and use a Sass variable is with a dollar sign, as shown in answer A. Option B uses equals signs and omits the dollar sign, which is not valid in Sass. Option C uses the at symbol, which is incorrect for Sass variables. Option D mixes syntax from CSS custom properties and JavaScript-style declarations, which is not valid in Sass.
In Sass, which of the following examples demonstrates correctly nested selectors for styling links inside a navigation bar?
Explanation: Nested selectors in Sass use curly braces, where child selectors are placed inside the block of the parent, as shown in the correct answer. Option B incorrectly places a colon after the child selector, which is invalid syntax. Option C is valid CSS, but does not use Sass's nesting feature. Option D incorrectly uses an at symbol, which is not used in this context in Sass.
Which code snippet properly defines and includes a Sass mixin for a border radius property?
Explanation: The correct answer uses @mixin to define and @include to use the mixin, matching Sass syntax. Option B lacks the @mixin and @include keywords, making it incorrect. Option C confuses the keywords' order and lacks proper definition. Option D misuses the dollar sign and omits correct mixin syntax, resulting in invalid Sass.
How would you create and include a Sass partial named '_variables' in your main Sass file?
Explanation: Sass partials begin with an underscore and are imported without the underscore or file extension. Option A correctly creates a partial and imports it. Option B uses the wrong import syntax and file extension. Option C uses @include instead of @import, which is reserved for mixins. Option D uses an illegal file name with a dollar sign and mixes up the partial import syntax.
What is the correct way to share a set of CSS rules using inheritance in Sass, as shown in the following scenario: both '.alert' and '.warning' should have bold text?
Explanation: Sass uses the percent sign to define a placeholder selector for inheritance, and @extend is used to inherit its styles, as shown in the correct answer. Option A incorrectly uses a dot alongside the percent sign, which is not valid. Option C treats the placeholder as a variable and uses an incorrect include syntax. Option D inappropriately uses an ampersand and omit the necessary @ symbol in @extend.