gpt4 book ai didi

ruby-on-rails - CSS 需要语法

转载 作者:行者123 更新时间:2023-12-03 16:04:49 25 4
gpt4 key购买 nike

在我的许多 RubyOnRails 应用程序中,我多次需要 CSS 样式表,实际上我需要揭开一些事情的神秘面纱。

有什么区别:

//=require mystyles


*=require mystyles

两者似乎都有效,那么有什么区别呢?

这是 Assets 管道的一部分还是 SASS 的一部分,或者只是简单的 CSS?

最佳答案

对于样式表,您给出的两个示例完全相同,但是 //=语法是唯一适用于 Javascript 的语法。您还需要在开头 ( /* ) 和 require 块末尾的关闭注释 ( */ ) 使用标准 CSS 注释,以使其忽略 Assets 管道以外的任何内容:

/* ...
*= require mystyles
*= require_self
*/

这些 require 指令只是 Assets 管道的一部分,而不是 CSS 或 SASS。要包含 CSS 或 SASS 的样式表,您可以使用 @import正如 Blieque 在他的评论中所说的那样。

查看 manifest files and directives section of the Asset Pipeline guide在 Ruby on Rails 指南站点上,了解差异的更详细说明。还有一个警告可能会引起人们的兴趣:

If you want to use multiple Sass files, you should generally use the Sass @import rule instead of these Sprockets directives. Using Sprockets directives all Sass files exist within their own scope, making variables or mixins only available within the document they were defined in.

关于ruby-on-rails - CSS 需要语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20294823/

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