将 .less css 定义包装在命名空间中
我只想在网页的特定元素中使用 twitter bootstrap CSS。
我尝试像下面的代码那样做。但将其编译为 css 文件后,没有任何输出。如果我将 @import
移到 #my_div
之外,那么我就获得了 twitter boostrap 的所有 css 定义。
#my_div {
@import "../twitter_bootstrap/lib/bootstrap.less";
}
如何命名 less css
文件?
I wanted to use twitter bootstrap CSS only in a specific element in my web page.
I tried to do it like in code below. But after compiling this to a css file nothing was outputted. If I moved @import
outside #my_div
then I got all css definitions for twitter boostrap.
#my_div {
@import "../twitter_bootstrap/lib/bootstrap.less";
}
How can I namespace a less css
file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我没有在实时站点上使用
less
,也没有手动进行编译,因此这是一个“简单”版本。它不像其他方法那样自动化,但可能适用于某些用户。编辑
bootstrap.css
/bootstrap-responsive.css
<前><代码>.tb {
// 复制/粘贴整个 bootstrap.css
}
使用 less 重新编译或使用在线 less 编译器 - http://winless.org/online-less-compiler
编辑现在-编译的文件并将
body {}
CSS 声明更改为tb {}
。使用新的 CSS 文件。
将“引导”内容放入
I am not using
less
on the live site, nor am I manually doing the compiling so this is kind of a "simple" version. It's not as automated as the others but may apply to some users.Edit
bootstrap.css
/bootstrap-responsive.css
Recompile with less or use an online less compiler - http://winless.org/online-less-compiler
Edit the now-compiled file and change
body {}
CSS declarations totb {}
.Use the new CSS file.
Place your "bootstrapped" content inside a
<div class='tb'></div>
LESS 文档有一个关于命名空间的部分。
因此,您可以在单独的文档中定义您的 lib:
在要编译的 CSS 文件的开头导入此文件并使用以下说明:
LESS documentation has a section about namespaces.
So you could define your lib in a separate document:
import this file at the beginning of the CSS file to be compiled and use these instructions:
我就是这样做的。这发生在下载的或从 git 克隆的 bootstrap 文件夹的根目录中。
然后运行 less style.less >样式.css
This is how I have done it. This takes place in the root of the bootstrap folder that is downloaded, or cloned from git.
Then run less style.less > style.css
以下是我的做法,基于上面的 majgis 的 github 分支:
bootstrap-ns.less:
namespace.less:
然后您在 html 页面中引用 bootstrap-ns.less 。这是用 dotLESS 测试的。
Here is how I did it, based on majgis's github fork above:
bootstrap-ns.less:
namespace.less:
You then reference bootstrap-ns.less in your html page. This was tested with dotLESS.
如果您可以控制编译参数,只需将
strictImports
设置为 false 并按照您的预期工作,一切都应该没问题。考虑查看 less-strictimports 或在此 问题。if you have control over the compilation parameters just set
strictImports
to false and work as you intended to everything should be fine. consider looking at less-strictimports or at this issue.