1

我有一个Rails 3.2应用程序,其中每个用户都有自己的子域。他能够改变一些事物的外观和感觉。在Bootstrap之前我曾经这样做过的方式是:我可以根据Bootstrap LESS变量动态编译新的CSS吗?

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)我的方法错了吗?我认为它会更干净,但我开始怀疑。

回答

0

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

@import "bootstrap_and_overrides.css.less"; 

而这一切了照顾。更清洁!