gpt4 book ai didi

ruby-on-rails-3 - Rails3.1-如何在某些 View 中包含css文件,而在其他 View 中不包含css文件?

转载 作者:行者123 更新时间:2023-12-04 04:52:17 24 4
gpt4 key购买 nike

在rails 3.1中,似乎所有css.scss文件都合并为1个文件。如果我只想将css文件包含在某些 View 中怎么办?就像我是否希望admin.css.scss包含在管理页面中,而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'

关于ruby-on-rails-3 - Rails3.1-如何在某些 View 中包含css文件,而在其他 View 中不包含css文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7655937/

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