是否可以在CSS评论中为mixins使用LESS变量?我需要那些精神.
例如(不工作/仅替换图像路径):
.sprite (@width) {
/** sprite: sprite-@{width}; sprite-image: url('../img/@{width}/sprite-@{width}.png'); sprite-layout: vertical */
.picture {
background-image: url('../img/@{width}/picture.png'); /** sprite-ref: sprite-@{width}; */
}
}
.sprite(800);
Run Code Online (Sandbox Code Playgroud)
额外问题:在使用lessc编译后,我可以阻止background-image和sprite-comment之间的换行符吗?
不,你不能在注释中使用变量。
添加一个被浏览器忽略的属性“comment”怎么样?
您可以尝试使用转义字符串,例如
prop: ~"url('blah'); /* comment */";
Run Code Online (Sandbox Code Playgroud)
但它会产生 2 个分号(有效的 CSS)并且非常hacky。