Sass/SCSS Nesting
Nesting selectors in Sass
Basic Nesting
.nav {
background: #333;
ul { # nested selector
list-style: none;
}
li {
display: inline-block;
}
}
Parent Selector (&)
.button {
background: blue;
&:hover { # .button:hover
background: darkblue;
}
&.active { # .button.active
font-weight: bold;
}
}
Nesting Properties
.box {
font: { # nest properties with same prefix
family: Arial;
size: 16px;
weight: bold;
}
}
BEM with &
.card {
background: white;
&__title { # .card__title (element)
font-size: 1.5rem;
}
&--featured { # .card--featured (modifier)
border: 2px solid gold;
}
}