0
0
SASSmarkup~5 mins

Parent selector with & in SASS - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the & symbol represent in Sass?
The & symbol represents the parent selector. It lets you refer back to the current selector inside nested styles.
Click to reveal answer
beginner
How would you write a hover style for a button using the parent selector & in Sass?
You write it like this:<br>
button {<br>  &:hover {<br>    color: red;<br>  }<br>}
<br>This means: when the button is hovered, change its color to red.
Click to reveal answer
intermediate
Can you use <code>&</code> to create a modifier class like <code>.btn-primary</code> inside <code>.btn</code>?
Yes! You can write:<br>
.btn {<br>  &-primary {<br>    background: blue;<br>  }<br>}
<br>This creates a class .btn-primary with the styles inside.
Click to reveal answer
intermediate
What happens if you use & inside a nested selector like .menu > li?
The & will be replaced by the full parent selector. For example:<br>
.menu {<br>  > li {<br>    color: green;<br>  }<br>}
<br>means .menu > li in CSS.
Click to reveal answer
beginner
Why is using & helpful in writing Sass?
It helps keep your code DRY (Don't Repeat Yourself). You can write nested styles that relate to the parent without repeating the full selector. It makes your code cleaner and easier to maintain.
Click to reveal answer
In Sass, what does &:hover inside a selector block do?
ATargets the hover state of the parent selector
BCreates a new unrelated selector
CTargets all child elements
DRemoves the parent selector
How would you write a nested class .card-active inside .card using &?
A.card { &-active { ... } }
B.card { .active { ... } }
C.card-active { ... }
D.card { & .active { ... } }
What will this Sass code compile to?<br>
.nav { > li { color: red; } }
A.nav li { color: red; }
Bli &gt; .nav { color: red; }
C.nav &gt; li { color: red; }
D.nav &gt; .li { color: red; }
Can & be used multiple times inside nested selectors?
AOnly if inside media queries
BNo, only once per block
COnly in the root selector
DYes, it always refers to the parent selector
Which of these is a benefit of using & in Sass?
AAutomatically adds vendor prefixes
BAvoids repeating selectors and keeps code clean
CRemoves the need for classes
DMakes CSS slower to load
Explain how the parent selector & works in Sass and give an example of its use.
Think about how you write hover styles or modifier classes inside a main class.
You got /3 concepts.
    Describe a situation where using & in Sass helps keep your code cleaner and easier to maintain.
    Consider writing styles for buttons with hover and active states.
    You got /3 concepts.