CSS需要语法 [英] CSS require Syntax

查看:70
本文介绍了CSS需要语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在许多RubyOnRails应用程序中都多次需要CSS样式表,而实际上,我需要一些神秘的东西.

I have required CSS stylesheets many times in many of my RubyOnRails applications, and actually i need a few things demystified.

两者之间有什么区别

//=require mystyles

*=require mystyles

两者似乎都起作用,所以有什么区别?

Both seem to work, so what is the difference?

这是资产管道的一部分还是SASS的一部分,还是只是普通CSS?

And is this a part of the asset pipeline or a part of SASS or just plain CSS?

推荐答案

您提供的两个示例与样式表完全相同,但是//=语法是唯一适用于Javascript的语法.您还需要在require块的开始(/*)和结束注释(*/)处添加标准CSS注释,以使其对资产管道以外的任何内容都被忽略:

The two examples you gave are exactly the same for stylesheets, however the //= syntax is the only one that works for Javascript. You also need a standard CSS comment at the start (/*) and a close comment (*/) at the end of the require block to make it ignored to anything but the asset pipeline:

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

这些require指令仅是资产管道的一部分,而不是CSS或SASS.要包括CSS或SASS的样式表,您可以使用Blieque在其评论中所述的@import规则.

These require directives are only part of the asset pipeline, not CSS or SASS. To include a stylesheet for CSS or SASS, you would use a @import rule as Blieque stated in his comment.

在资产管道指南"中的清单文件和指令部分中. Ruby on Rails指南站点提供了有关差异的更详细说明.可能还会引起您注意的警告:

Check out the manifest files and directives section of the Asset Pipeline guide on the Ruby on Rails guide site for a more detailed explanation of the difference. There is also a warning given there that might be of interest:

如果要使用多个Sass文件,通常应使用 Sass @import规则而不是这些Sprockets指令.使用 Sprockets指令将所有Sass文件都存在于它们自己的范围内, 使变量或混合仅在文档中可用 定义在.

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.

这篇关于CSS需要语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆