我可以将 Partials 导入到 SASS 中的 Partials 中吗? [英] Can I import Partials into Partials in SASS?

查看:85
本文介绍了我可以将 Partials 导入到 SASS 中的 Partials 中吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Sass 设计一个新网站.
最初我的 style.scss(编译的主要 SCSS 文件)导入了 general.scss(我在其中定义了变量)和各种页面(例如 homepage.scss).它运作良好.我尝试重构 homepage.scss 以仅导入其各个部分的 Scss(例如 section-a.scss).令人惊讶的是,Sass 编译器 (Prepros) 不再识别所有变量.

I'm using Sass to style a new website.
Originally my style.scss (the main SCSS file which compiles) imported general.scss (where I defined variables) and the various pages (such as homepage.scss). It worked well. I than tried to refactor homepage.scss to just import Scss of its' various sections (such as section-a.scss). Surprisingly all the variables aren't recognized anymore by the Sass compiler (Prepros).

我的问题是:

  1. 我可以在 SASS 中将部分导入到部分中吗?
  2. 我可以在所有其他部分中使用在导入到主 scss 文件(编译的文件)的部分中声明的变量吗?

不用说,所有部分文件名都以下划线开头.

Needless to say, all of the partial file names begin with an underscore.

谢谢!

推荐答案

它必须与您放置导入的顺序有关.

It must have to do with the order you are placing your imports.

这应该是这样的:(我不记得 SCSS 语法是什么……但这应该解释一下)

That should work something like this: (I don't remember what the SCSS syntax is... but this should explain)

// primary file master.scss or whatever importing partials...
@import 'reset';
@import 'variables';
@import 'styles-etc';


// variables file / importing other partials
@import 'variables/space';
@import 'variables/color';
@import 'variables/break-points';


// styles file
body {
  background: $color; // from variables/color...
}

我从来没有建议任何人使用 bootstrap...但是如果你看一下它的结构,你可能会看到很多这样的——作为一个例子.

I've never ever suggested anyone use bootstrap... but if you look at it's structure you'll probably see a lot of this - as an example.

这篇关于我可以将 Partials 导入到 SASS 中的 Partials 中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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