gpt4 book ai didi

ruby-on-rails-3 - 如何在 Rails 3.1 中加载 CSS 框架?

转载 作者:行者123 更新时间:2023-12-03 10:21:23 25 4
gpt4 key购买 nike

我正在尝试将 CSS 框架 Blueprint 加载到我的 Rails 3.1 应用程序中。

在 Rails 3.0+ 中,我的 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 文件的正确方法是什么?

目前,我在 app/assets/stylesheets/中有蓝图目录

我的 app/assets/stylesheets/application.css 看起来像:
/*
* 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 做一些事情,以便它加载必要的蓝图文件吗?如果是这样,如何?

其次,我将如何提供某种条件来检查 IE8,以加载 blueprint/ie.css?

编辑:

嗯,再次重新加载应用程序的网页。 Rails 3.1 确实包含蓝图文件。即使 css 文件在一个文件夹中(在这种情况下:app/assets/stylesheets/blueprint。)

这让我有两个问题
  • 应该如何申请如果是 IE 8 条件使用SASS?
  • 如何使用 SASS 加载打印格式的 css 文件(即 <%= stylesheet_link_tag 'blueprint/print', 'media' => 'print' %>)?
  • 最佳答案

    尽管 Rails 3.1 (RC) 允许使用 SASS 文件——但它并没有强制使用。
    您的 /public/stylesheets 中的文件仍然会很好地送达。

    如果您希望激活 SASS 解析器(并使用新框架),请重命名您的 my_styles.css成为 my_styles.css.scss并将其放入 /app/assets/stylesheets文件夹。然后只包括您的 application.css在您的 application.erb.html在取消注释掉 require_self/require_tree 行之后。

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

    至于 IE 8 的事情。 IE 中有一个 bug 并不总是执行条件,所以试试

    <!--[if IE 8.000]><!-->
    <link href='./design/style-ie-8.css' rel='stylesheet' type='text/css' />
    <!--<![endif]-->

    尝试重置解析器以执行规则有点麻烦

    关于ruby-on-rails-3 - 如何在 Rails 3.1 中加载 CSS 框架?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6115015/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com