SASS Concatenate class name?

百般思念 提交于 2019-12-19 10:46:13

问题


I got a LESS file from this a Date-picker plugin and want to convert it to SASS.

But in the LESS, it concates a class name like this:

//LESS
.dropdown{
    &-inline{
    }
}

Result:

.dropdown-inline ...

I tried many things in SASS like #{-inline} or #{"-inline"} but it doesn't work.

I tried googling and found a year-old article saying it's impossible in SASS. I can't found recent post about this issue. Is it possible now? How?

Thanks


回答1:


This is not possible before version 3.2 but will be eventually. Just like LESS, the syntax will use &.

With updated scss, you can now use the interpolation syntax &-- to DRY up your style files.




回答2:


Just moved from css to scss I ran in to this question and was disappointed until I found out it is not up-to-date. Found the correct answer here: https://css-tricks.com/the-sass-ampersand/#article-header-id-12.

It is now possible with the following syntax:

.add-some {
    &-red {
        color: red;
    }
}

Results, as expected, to:

.add-some-red {
    color: red;
}


来源:https://stackoverflow.com/questions/16432146/sass-concatenate-class-name

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!