如何在 Rails 3.1 中加载 CSS 框架? [英] How does one load a CSS framework in Rails 3.1?

查看:34
本文介绍了如何在 Rails 3.1 中加载 CSS 框架?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 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.加载这些蓝图 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/

我的 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.)

这给我留下了两个问题

  1. 应该如何使用 SASS 应用 if lt IE 8 条件?
  2. 如何使用 SASS 加载打印格式的 css 文件(即 <%= stylesheet_link_tag 'blueprint/print', 'media' => 'print' %>)?

推荐答案

尽管 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 文件夹.然后在您的 application.erb.html 中取消注释掉 require_self/require_tree 行之后,只包含您的 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.

有关更多信息,这是我在谷歌快速搜索后找到的博客:http://www.rubyinside.com/how-to-rails-3-1-coffeescript-howto-4695.html

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 中有一个 bug,不总是执行条件,所以试试

As for the IE 8 thing. There was a bug in IE not not always executing conditions, so try

<代码><!--[如果 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆