如何在Rails 3.1中加载CSS框架? [英] How does one load a CSS framework in Rails 3.1?
问题描述
我正在尝试将CSS框架Blueprint加载到我的Rails 3.1应用程序中.
I am trying to load a CSS framework, Blueprint, onto my Rails 3.1 application.
在Rails 3.0+中,我的views/layouts/application.html.erb中会有类似的内容:
In Rails 3.0+, I would have something like this in my views/layouts/application.html.erb:
<%= stylesheet_link_tag 'blueprint/screen', 'application' %>
<%= stylesheet_link_tag 'blueprint/print', 'media' => 'print' %>
<!--[if lt IE 8]>
<%= stylesheet_link_tag 'blueprint/ie' %>
<![endif]-->
但是,Rails 3.1现在使用SASS.加载这些Blueprint CSS文件的正确方法是什么?
However, Rails 3.1 now uses SASS. What would be the proper way to load these Blueprint CSS files?
当前,我在app/assets/stylesheets/
Currently, I have the blueprint dir in app/assets/stylesheets/
我的应用程序/资产/样式表/application.css如下:
My app/assets/stylesheets/application.css looks like:
/*
* This is a manifest file that'll automatically include all the stylesheets available in this directory
* and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
* the top of the compiled file, but it's generally better to create a new file per style scope.
*= require_self
*= require_tree .
*/
我应该对application.css做些什么,以便它加载必要的蓝图文件吗?如果可以,怎么办?
Should I do something with application.css so that it loads the necessary Blueprint files? If so, how?
第二,我如何提供某种条件来检查IE8,以加载blueprint/ie.css?
Second, how would I provide some kind of condition to check for IE8, to load blueprint/ie.css?
嗯,再次重新加载应用程序的网页. Rails 3.1确实包含了蓝图文件.即使css文件位于文件夹中(在这种情况下为app/assets/stylesheets/blueprint.)
Hmmm, reloading the app's web page again. Rails 3.1 does include the Blueprint files. Even if the css files are in a folder (in this case: app/assets/stylesheets/blueprint.)
哪个让我有两个问题
- 如何使用SASS应用 if IE 8 条件?
- 如何使用SASS加载打印格式的CSS文件(即<%= stylesheet_link_tag'blueprint/print','media'=>'print'%>)?
- How should one apply the if lt IE 8 condition using SASS?
- How does one load a css file for the print format (i.e. <%= stylesheet_link_tag 'blueprint/print', 'media' => 'print' %>) using SASS?
推荐答案
即使Rails 3.1(RC)允许使用SASS文件,也不会强制使用.
/public/stylesheets
中的文件仍然可以正常投放.
Even though Rails 3.1 (RC) allows use of SASS files-- it doesn't force it.
Files in your /public/stylesheets
will still be served just fine.
如果您希望激活SASS解析器(并使用新框架),请将您的my_styles.css
重命名为my_styles.css.scss
并将其放置在/app/assets/stylesheets
文件夹中.然后取消注释其中的require_self/require_tree行,然后在application.erb.html
中仅包含您的application.css
.
If you wish to activate the SASS parser (and utilize the new framework), rename your my_styles.css
to be my_styles.css.scss
and put it in the /app/assets/stylesheets
folder. Then include just your application.css
in your application.erb.html
after uncommenting out the require_self / require_tree lines in it.
For more info, here is a blog i pulled up after a quick google search: http://www.rubyinside.com/how-to-rails-3-1-coffeescript-howto-4695.html
对于IE 8来说. IE中存在一个错误,并非总是执行条件,因此请尝试
As for the IE 8 thing. There was a bug in IE not not always executing conditions, so try
<!--[if IE 8.000]><!-->
<link href='./design/style-ie-8.css' rel='stylesheet' type='text/css' />
<!--<![endif]-->
<!--[if IE 8.000]><!-->
<link href='./design/style-ie-8.css' rel='stylesheet' type='text/css' />
<!--<![endif]-->
有点黑客试图重置解析器以执行规则
its a bit of hackery to try and reset the parser to execute the rule
这篇关于如何在Rails 3.1中加载CSS框架?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!