Propaganistas Propaganistas - 1 month ago 5
Sass (Sass) Question

Does SASS support element specification as nested selector?

Let's say you have this SASS definition (unreal example):

.class {
margin: 1px;
background: black;
color: white;

&:hover {
color: red;
}
}

a.class {
margin: 1px;
background: black;
color: yellow;

&:hover {
color: blue;
}
}


Now, can we put the
a
specification of the same class as a nested selector? E.g. something like this (pseudo-code):

.class {
margin: 1px;
background: black;
color: white;

&:hover {
color: red;
}

// Some selector to show that the current class
// should be applied to this element (?)
a.& {
color: yellow;

&:hover {
color: blue;
}
}
}

Answer

I have a solution. its a little bit tricky, but its works fine.

.class {
    color: yellow;

    &:hover {
        color: blue;
    }
    &[href] {
        color: white;

        &:hover {
            color: red;
        }
    }
}

Working Fiddle

Comments