How to combine several Font Awesome classes into one selector using LESS?

天大地大妈咪最大 提交于 2019-12-10 12:23:16

问题


I'm trying to nest a bunch of font awesome styles into a single css class I can use whenever I'd like. However, I'm getting an error with "Undeclared Mixin".

My .less file looks something like this:

@import (reference) "../Content/bootstrap/font-awesome/font-awesome.less";

.step-current {
    .fa;
    .fa-play;
    .text-success;
}

In this case all I'd like to do is apply the styles .fa, .fa-play, and .text-success whenever I use the class step-current on an element. However, I'm getting an error when I try to compile this less file (using Web Compiler 2015).

.fa-play is an Undeclare Mixin.

Obviously I could just go like this: class="fa fa-play text-success" within my tag but I'd really like to know if it's possible to do the above.

Thanks


回答1:


LESS is tripping up because Font Awesome doesn't style .fa-play, only .fa-play:before. Get around this by using LESS's :extend syntax (see also this css-tricks write-up/tutorial). The key is the all keyword, which will bring in the :before styles.

.custom-class {
    &:extend(.fa, .fa-play all);
    .text-success
}

(Just guessing about what to do with your .text-success - that doesn't appear to be part of Font Awesome… but then it wasn't part of your problem, so I guess it doesn't matter. You might need to use :extend to pull it in, or you might be able to just use it as a normal old LESS mixin as I did above.)



来源:https://stackoverflow.com/questions/39279840/how-to-combine-several-font-awesome-classes-into-one-selector-using-less

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