SASS全局变量未传递给局部变量 [英] SASS global variables not being passed to partials

查看:155
本文介绍了SASS全局变量未传递给局部变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我有一个结构可以在3.0.x中正常工作,现在它会因undefined variable错误而中断.

  • 局部
    • _base.css.sass
    • _header.css.sass
  • main.css.sass
  • application.css.sass

application.css.sass:

//=require 'main'

main.css.sass:

@import 'partials/base'
@import 'partials/header'

非常简单的东西.

我在_header.css.sass上遇到错误 因为它使用了_base.css.sass

上定义的变量

我以前没有这个错误,对我来说这没有意义,因为我们在导入_header.css.sass的同一上下文中将这些变量导入到_base.css.sass上.

我也必须在每个局部上导入_base.css.sass吗? 如果main.css.sass不能在您需要的部分中使用全局变量,那么需要全局变量有什么意义呢?

如果我的结构完全错误,请给我另一种选择,我很乐意提出建议.

解决方案

您不能使用//=require来包含诸如混入和变量之类的动态" SASS内容,因为它仅用于包含最静态"的内容(像纯CSS).您必须@import application.css.sass中的所有文件. Railscasts在 episode#268 中提供了很好的解释./p>

Basically I have a structure that used to work perfectly in 3.0.x and now it breaks with undefined variable errors.

  • partials
    • _base.css.sass
    • _header.css.sass
  • main.css.sass
  • application.css.sass

the application.css.sass:

//=require 'main'

the main.css.sass:

@import 'partials/base'
@import 'partials/header'

Pretty simple stuff.

I get an error on _header.css.sass because it uses a variable defined on _base.css.sass

I didn't have this error before, and it makes no sense to me, since we're importing those variables on the _base.css.sass in the same context we are importing the _header.css.sass.

Am I going to have to import the _base.css.sass on every partial too? What is the point of the main.css.sass requiring global variables if they cannot be used in the own partials you are requiring?

If my structure is completely wrong, please give me an alternative, I'd love suggestions.

解决方案

You can't use //=require to include "dynamic" SASS stuff like mixins and variables, because that's used just for including the most "static" stuff (like pure CSS). You have to @import all your files in application.css.sass. Railscasts provides good explanation of this in episode #268.

这篇关于SASS全局变量未传递给局部变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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