CSS 行使用 stylesheet_link_tag 重复

发布于 2024-12-05 22:15:50 字数 1013 浏览 4 评论 0原文

我正在尝试在 Rails3 应用程序中订购样式表,但我遇到了使用 *stylesheet_link_tag* 帮助程序重复行的问题。

在 app/views/layouts/application.html.erb 中

<%= stylesheet_link_tag    :reset, :application, :event_calendar, :cache => false %>

生成的源代码中:

<link href="/assets/reset.css?body=1" media="screen" rel="stylesheet" type="text/css" />
<link href="/assets/application.css?body=1" media="screen" rel="stylesheet" type="text/css" />
<link href="/assets/event_calendar.css?body=1" media="screen" rel="stylesheet" type="text/css" />
<link href="/assets/reset.css?body=1" media="screen" rel="stylesheet" type="text/css" />
<link href="/assets/event_calendar.css?body=1" media="screen" rel="stylesheet" type="text/css" />

app/assets/stylesheets/ 文件夹的内容:

calendar (master *)$ ls app/assets/stylesheets/
application.css     event_calendar.css  reset.css

使用 *javascript_include_tag* 帮助程序出现同样类型的问题,我认为两者都可以相关。

I'm trying to order my stylesheets in a rails3 app, but I've got an issue with the lines repeating themselves using the *stylesheet_link_tag* helper.

In app/views/layouts/application.html.erb

<%= stylesheet_link_tag    :reset, :application, :event_calendar, :cache => false %>

In produced source code:

<link href="/assets/reset.css?body=1" media="screen" rel="stylesheet" type="text/css" />
<link href="/assets/application.css?body=1" media="screen" rel="stylesheet" type="text/css" />
<link href="/assets/event_calendar.css?body=1" media="screen" rel="stylesheet" type="text/css" />
<link href="/assets/reset.css?body=1" media="screen" rel="stylesheet" type="text/css" />
<link href="/assets/event_calendar.css?body=1" media="screen" rel="stylesheet" type="text/css" />

Content of app/assets/stylesheets/ folder:

calendar (master *)$ ls app/assets/stylesheets/
application.css     event_calendar.css  reset.css

The same kind of problem appears using *javascript_include_tag* helper, I think both can be related.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

删除→记忆 2024-12-12 22:15:50

如果您使用资产管道,您只需要包含 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 . 命令,将自动包含同一目录中的所有文件。

只需放入...

<%= stylesheet_link_tag :application, :cache => false %>

如果您需要将 reset.css 放在第一位,您可以在 application.css 中指定顺序

*= require reset
*= require_self
*= require_tree . 

If you're using the asset pipeline you only need include application.css as inside that there should be lines 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 . 
*/

Don't be fooled by the fact its commented out, this will be processed and will automatically include all the files in the same directory because of the require_tree . command.

Just put...

<%= stylesheet_link_tag :application, :cache => false %>

You can specify the order within application.css if you need your reset.css to come first

*= require reset
*= require_self
*= require_tree . 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文