@将较少的文件导入有限的范围 [英] @Import of less files into a limited scope
问题描述
我想从另一个较少的文件中导入所有样式,但是要导入到有限的范围内.我正在尝试:
I want to import all styles from another less file, but into a limited scope. I'm trying this:
"my-site.less"
"my-site.less"
.wrapper-class {
@import "path/to/styles.less";
}
但这根本不起作用.我正在使用基于浏览器的less.js选项,并且可以看到实际执行导入时运行的GET语句.但是生成的CSS不包含其他工作表中的任何样式.如果我这样做的话,它会起作用:
But this doesn't work at all. I'm using the browser-based less.js option, and I can see the GET statement that is run when it actually does the import. But the resultant CSS does not contain any of the styles from the other sheet. If I do it like this, it works:
.wrapper-class
{
/* ... */
}
@import "path/to/styles.less";
但这违背了最初的目的.那么,有什么办法可以在Less中做到像这样的有限范围的@import吗?谢谢!
But this defeats the original purpose. So is there any way to do a limited-scope @import like this in Less? Thanks!
推荐答案
According to the css-spec, the @import
-declaration has to come before all other declarations in the css-file. So your @import
inside the rule is expected to fail. I guess the @import
ing at the end of the file not failing is goodwill of the browser-vendors.
我想LESS将遵守相同的规则.
I guess LESS will abide by the same rules.
问题是,为什么要对这些样式进行范围划分?有了正确的声明,就没有必要了.
the question is, why do you want to have those styles scoped? With proper declarations, this should not be necessary.
这篇关于@将较少的文件导入有限的范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!