加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails-3 – Rails3.1 – 如何在某些视图中包含css文件而

发布时间:2020-12-16 19:33:06 所属栏目:百科 来源:网络整理
导读:似乎在rails 3.1中,所有css.scss文件都合并为1个文件.如果我想将css文件仅包含在某些视图中,该怎么办?就像我想要管理页面中包含admin.css.scss和home / about / contact页面中的main.css.scss一样. 解决方法 在Rails 3.1中,如果application.css如下所示,所
似乎在rails 3.1中,所有css.scss文件都合并为1个文件.如果我想将css文件仅包含在某些视图中,该怎么办?就像我想要管理页面中包含admin.css.scss和home / about / contact页面中的main.css.scss一样.

解决方法

在Rails 3.1中,如果application.css如下所示,所有样式表将合并到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 . 
*/

这是由于* = require_tree.

您可以要求特定的样式表:

*= require main

否则,在您的布局中,您写道:

%head
 = yield :head

并在您的页面中:

= content_for :head do
 = stylesheet_link_tag 'stylesheet'

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读