You can just get it from cached &
. Here is a simple BEM example:
HTML
<ul class="pagination">
<li class="pagination__item">
<a class="pagination__link" href="#">
Page 1
</a>
</li>
<li class="pagination__item pagination__item--active">
<a class="pagination__link" href="#">
Page 2
</a>
</li>
</ul>
SCSS
$gray-very-light: #ccc;
.pagination {
display: flex;
padding: 0;
list-style: none;
$this: &;
&__item {
border: 1px solid $gray-very-light;
& + & {
margin-left: .5rem;
}
}
&__link {
display: block;
padding: .25rem .5rem;
text-decoration: none;
&:hover,
#{$this}__item--active & { // Here we get .pagination from $this variable
background-color: $gray-very-light;
}
}
}
Output CSS
.pagination {
display: flex;
padding: 0;
list-style: none;
}
.pagination__item {
border: 1px solid #ccc;
}
.pagination__item + .pagination__item {
margin-left: .5rem;
}
.pagination__link {
display: block;
padding: .25rem .5rem;
text-decoration: none;
}
.pagination__link:hover,
.pagination__item--active .pagination__link {
background-color: #ccc;
}
#{$this} not working for me, I even update sass to version 1.26.5