“Additive” property values with LESS mixin

旧巷老猫 提交于 2019-12-02 07:53:50

问题


I'm looking for a feature that may or may not be available in LESS.

I have a mixin that adds a "glow" with box-shadow, which I use on various elements - buttons, inputs etc.

.glow() {
    box-shadow: 0 0 5px skyBlue;
}

What I'm looking for is a way to make the mixin add the box-shadow as a new comma-seperated value if the element already has a box-shadow.

So, I want this:

.button {
    box-shadow: inset 0 5px 10px black;
    .glow();
}

To compile to this:

.button {
    box-shadow: inset 0 5px 10px black, 0 0 5px skyBlue;
}

I think I recall seeing a similar feature in SASS, but I can't find it anywhere now.

Does this feature exist in LESS, or is there some alternative way to achieve a similar result?


回答1:


The feature you're looking for is merge. You'd do this:

.glow() {
    box-shadow+: 0 0 5px skyBlue;
}
.button {
    box-shadow+: inset 0 5px 10px black;
    .glow();
}

Note that both rulesets need to use the + syntax for it to work.

Or, you could declare the glow rule as a variable:

@glow: 0 0 5px skyBlue;

.button {
    box-shadow: inset 0 5px 10px black, @glow;
}


来源:https://stackoverflow.com/questions/30644529/additive-property-values-with-less-mixin

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