我想知道是否有可能在不触及HTML的情况下附加Bootstrap glyphicon并将其用作LESS mixin,如下所示:
a {
.glyphicon;
.glyphicon-envelope;
}
任何帮助都将不胜感激。
答案 0 :(得分:8)
是的,你可以:
<强>少强>
@import "variables.less";
@import (reference) "glyphicons.less";
a {
.glyphicon;
.glyphicon-envelope;
}
将编译成以下CSS:
a {
position: relative;
top: 1px;
display: inline-block;
font-family: 'Glyphicons Halflings';
font-style: normal;
font-weight: normal;
line-height: 1;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
a:before {
content: "\2709";
}
请注意,如果您想在不使用完整Bootstrap CSS的情况下使用CSS或将字体定义添加到Less代码中,则不应将reference关键字与@import一起使用:
@font-face {
font-family: 'Glyphicons Halflings';
src: url('@{icon-font-path}@{icon-font-name}.eot');
src: url('@{icon-font-path}@{icon-font-name}.eot?#iefix') format('embedded-opentype'),
url('@{icon-font-path}@{icon-font-name}.woff') format('woff'),
url('@{icon-font-path}@{icon-font-name}.ttf') format('truetype'),
url('@{icon-font-path}@{icon-font-name}.svg#@{icon-font-svg-id}') format('svg');
}
还要考虑Less的extend feature:
<强>少强>
@import "variables.less";
@import (reference) "glyphicons.less";
a {
&:extend(.glyphicon);
&:extend(.glyphicon-envelope all);
}