【发布时间】:2016-03-03 16:27:03
【问题描述】:
我需要在类的正上方生成一些带有一些 cmets 的 CSS,在这些 cmets 中,我需要评估一些变量。我在 Sass 中成功地做到了这一点,但 Less 似乎没有相同的功能。
这是我需要的:
/**Header*/
.Header {
font-size: 1.5em;
}
这是我在 Sass 中的尝试:
@function str-replace($string, $search, $replace: '') {
$index: str-index($string, $search);
@if $index {
@return str-slice($string, 1, $index - 1) + $replace + str-replace(str-slice($string, $index + str-length($search)), $search, $replace);
}
@return $string;
}
@mixin rte_property($name) {
/**#{$name}*/
.#{str-replace($name, ' ', '')} {
@content;
}
}
@include rte_property(Header) {
font-size: 1.5em;
}
这是我在 Less 中的尝试:
.rte_element (@name, @rules) {
@className: e(replace(@name, " ", ""));
/**@{name}*/
.@{className} {
@rules();
}
}
.rte_element("Header 2", {
font-size: 1.5em;
});
Less 是否可以在 cmets 中插值/评估变量?如果有,怎么做?
【问题讨论】:
-
据我所知不可能有两个原因 - (1) Less 不计算 cmets 内的变量 (2) Less 编译器不允许在选择器块之外打印属性值对(因为它是无效的 CSS),因此甚至无法通过将注释打印为属性 + 值来进行修改。
标签: less