博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[SCSS] Organize SCSS into Multiple Files with Partials
阅读量:4332 次
发布时间:2019-06-06

本文共 2283 字,大约阅读时间需要 7 分钟。

Tired of dealing with monolithic CSS files? Are requests for multiple CSS files hurting your performance? In this lesson we learn how to separate our styles with SCSS partials, and how SCSS imports compile to one file so there's only one request.

 

Things to know:

  • If importing partial file, won't generate a new css file
  • If importing normal scss file, it will generate a new css file

So when we should use partial import or not, you can think that whether this file should be used when app first loading? If it yes, then use partial import, if not, then normal import. The reason behind that is because browser will loading main css (the main.scss file that import other scss files ) file first. After this main.css file loaded, then browser will start loading other css file. 

As you can see other.css which are import as normal import mode. "Content downloaded" happens after main.css file are downloaded.

 

  • Only partial file's variable can be shared accross the rest of partial file. But it also require you import that partial file which has variables defines into main.scss file before the rest partial files.
/** About using variable There are tow cases when using variable 1. none partial file (provider) + none partial file    Variable only available for its own file scope.    If you want to use one variable inside file A from file B    You have to import file A into file B. 2. partial file (provider) + none partial file    If you have an variable defined in partial file, and you want to    use it inside none partial file, you also need to import partial    file into none partial file. 3. partial file (provider) + partial file    If you have an variable defined in partial file A, and you want to use it    inside another partial file B, you have to import file A into main.scss file    before you import file B into main.scss. Then you can use variable inside file A    inside file B.*/@import "color";@import "partial";@import "other";.color {
color: $primary-color; // From _color}

 

_color.scss

$primary-color: lighten(red, 15%);.red {
color: $primary-color;}

 

_partial.scss

.l-border {
border-left: 5px solid $primary-color;}

 

other.scss

@import "color";.bg {
background-color: $primary-color;}

 

转载于:https://www.cnblogs.com/Answer1215/p/6683041.html

你可能感兴趣的文章
小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_3-5.PageHelper分页插件使用
查看>>
小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_5-6.微信扫码登录回调本地域名映射工具Ngrock...
查看>>
小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_5-8.用户模块开发之保存微信用户信息...
查看>>
代码片段收集
查看>>
vue-cli3创建项目时报错
查看>>
输入1-53周,输出1-53周的开始时间和结束时间
查看>>
实验二
查看>>
shell——按指定列排序
查看>>
crash 收集
查看>>
507 LOJ 「LibreOJ NOI Round #1」接竹竿
查看>>
UI基础--烟花动画
查看>>
2018. 2.4 Java中集合嵌套集合的练习
查看>>
精通ASP.NET Web程序测试
查看>>
vue 根据不同属性 设置背景
查看>>
51Nod1601 完全图的最小生成树计数 Trie Prufer编码
查看>>
Codeforces 1110D. Jongmah 动态规划
查看>>
android驱动在win10系统上安装的心酸历程
查看>>
优雅的程序员
查看>>
oracle之三 自动任务调度
查看>>
Android dex分包方案
查看>>