Angelos Chalaris Angelos Chalaris - 4 months ago 9
CSS Question

Nesting element+element selector in SCSS

As a newbie in SCSS I am wondering how to use its nesting for the element + element selector of CSS. Normally, in CSS, I would write something like:

.test{
color: red;
}
.test + label{
color: blue;
}


How can I nest the
+ label
selector inside the
.test
selector? Thanks in advance!

Answer

Upate: In this case all you need to do is to nest rules like this:

.test {
    color: red;
    + label {
        color: blue;
    }
}

However, you can also use the & selector to achieve the same effect like this:

.test {
    color: red;
    & +label {
        color: blue;
    }
}