【问题标题】:Can I dynamically compile new CSS based on Bootstrap LESS variables?我可以根据 Bootstrap LESS 变量动态编译新的 CSS 吗?
【发布时间】:2013-02-28 14:01:14
【问题描述】:

我有一个 Rails 3.2 应用程序,其中每个用户都有自己的子域。他能够改变一些事物的外观和感觉。在 Bootstrap 之前我这样做的方式是:

1) Keep a template of a customizable CSS file.

2) Solicit input for certain CSS settings via a form.

3) On form submission, write a new CSS file based on the template, but with the new settings.

4) Associate the new CSS file with that partiular subdomain, and serve it up when the subdomain is accessed via the main layout template.

这样做有点难看,但效果很好。此后,我通过 twitter-bootstrap-rails gem 迁移了应用程序以使用 Twitter Bootstrap。这使我能够清理大量代码。我现在要做的是清理这个 CSS 自定义功能。

我想仅基于更改 Twitter Bootstrap LESS 变量来进行新的 CSS 更改。我的子域的新 LESS 文件将像这样生成:

@bodyBackground: #ffffff;

@navbarLinkColor: #ffffff;

@navbarText: #ffffff;

@headingsColor: #666666;

@linkColor: #000000;

@navbarBackgroundHighlight: #000000;

@baseFontFamily: Verdana, Tahoma, Geneva, sans-serif;

请注意,此文件中只有variables。所有设置都在 Bootstrap 代码中。所以保存后我需要动态地重新编译所有的 Boostrap CSS。几个问题:

1) 这可能吗?如果这些变量已经在 Twitter Bootstrap 中设置为默认值,我该如何覆盖它们?

2) 我是不是走错了路?我以为它会更干净,但我开始怀疑了。

【问题讨论】:

    标签: twitter-bootstrap ruby-on-rails-3.1 ruby-on-rails-3.2 twitter-bootstrap-rails


    【解决方案1】:

    我需要做的就是将它添加到 LESS 文件的顶部:

    @import "bootstrap_and_overrides.css.less";
    

    这就解决了所有问题。干净多了!!!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-26
      • 1970-01-01
      • 2017-01-15
      • 1970-01-01
      相关资源
      最近更新 更多