CSS 包含单独的 Sass 文件的语法?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8061166/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Syntax to include separate Sass file?
提问by SkinnyG33k
I can't confirm that this syntax is best practice. I would like to reference an external Sass file and have it prepend it to my final CSS file, this way my Sass sheet looks more clean, and I'm only still only making one HTTP request.
我无法确认此语法是最佳实践。我想引用一个外部 Sass 文件并将其添加到我的最终 CSS 文件中,这样我的 Sass 表看起来更干净,而且我仍然只发出一个 HTTP 请求。
For example, take the "normalize" code and put it into a .sass file, then in my sass sheets simply refer to it:
例如,将“normalize”代码放入一个 .sass 文件中,然后在我的 sass 表中简单地引用它:
@import src/normalize
@import src/droidSans
rest of code here.....
It works fine so far, but I can't find anything concrete if I'm headed in the right direction. Also I am just making static templates for the time being... not using Rails at the moment.
到目前为止它运行良好,但如果我朝着正确的方向前进,我找不到任何具体的东西。另外,我暂时只是在制作静态模板……目前不使用 Rails。
I have been playing around with Sass for a few hours and I love it!!!
我已经和 Sass 玩了几个小时了,我喜欢它!!!
回答by Sampson
In order to prevent your partial from being converted into its own css file, prefix the filename with an underscore, _normalize.scss
. Then you can import it the way you've indicated you're doing already:
为了防止您的部分被转换成它自己的 css 文件,请在文件名前加上下划线_normalize.scss
. 然后您可以按照您已经指示的方式导入它:
@import "normalize";
Or import many files at once:
或者一次导入多个文件:
@import "normalize", "droidSans";
Or import from a relative directory:
或者从相对目录导入:
@import "folder/file"
Note the use of double-quotes and semi-colon; I'm using the SCSS syntax which is a later development to the SASS word. While both styles are valid, you may find yourself preferring one over the other depending on what other languages you dabble in.
注意双引号和分号的使用;我正在使用 SCSS 语法,这是 SASS 词的后期发展。虽然这两种风格都是有效的,但根据您涉足的其他语言,您可能会发现自己更喜欢一种。
Further reading can be found under Directives/Partialsin the documentation.