Sass Nesting for :hover does not work [duplicate]

2020-02-16 05:49发布

I've written this code, but it does not work. What is my problem?

.class {
    margin:20px;
    :hover {
        color:yellow;
    }
 }

2条回答
Juvenile、少年°
2楼-- · 2020-02-16 06:15

For concatenating selectors together when nesting, you need to use the parent selector (&):

.class {
    margin:20px;
    &:hover {
        color:yellow;
    }
}
查看更多
家丑人穷心不美
3楼-- · 2020-02-16 06:17

You can easily debug such things when you go through the generated CSS. In this case the pseudo-selector after conversion has to be attached to the class. Which is not the case. Use "&".

http://sass-lang.com/documentation/file.SASS_REFERENCE.html#parent-selector

.class {
    margin:20px;
    &:hover {
        color:yellow;
    }
}
查看更多
登录 后发表回答