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;
}

[SCSS] Organize SCSS into Multiple Files with Partials的更多相关文章

  1. 基于Picture Library创建的图片文档库中的上传多个文件功能(upload multiple files)报错怎么解决?

    复现过程 首先,我创建了一个基于Picture Library的图片文档库,名字是 Pic Lib 创建完毕后,我点击它的Upload 下拉菜单,点击Upload Picture按钮 在弹出的对话框中 ...

  2. How to effectively work with multiple files in Vim?

    Why not use tabs (introduced in Vim 7)? You can switch between tabs with :tabn and :tabp, With :tabe ...

  3. How to Upload multiple files to documentLibrary in one time

         In a Sharepoint 2013 website,we can upload one file to the documentlibrary by click "Uploa ...

  4. Uploading multiple files asynchronously by blueimp jquery-fileupload

    Uploading multiple files asynchronously by blueimp jquery-fileupload   Solved. Fiddle: http://jsfidd ...

  5. How to attach multiple files in the Send Mail Task in SSIS

    Let’s say you need to create a SSIS package that creates 2 files and emails the files to someone. Yo ...

  6. [SCSS] Organize Styles with SCSS Nesting and the Parent Selector

    SCSS nesting can produce DRYer code by targeting child elements without having to write the parent c ...

  7. 预编译scss以及scss和less px 转rem

    预编译scss步骤: 1 搜索ruby并安装,点击 2 安装sass: 3 在hubuilder工具中设置预编译: 触发命令地址为ruby安装地址 命令参数为 %FileName% %FileBase ...

  8. [SCSS] Convert SCSS Variable Arguments to JavaScript

    We will learn how to convert variable arguments by using rest operator in JavaScript. .sass-btn { co ...

  9. Retrofit Upload multiple files and parameters

    Retrofit 的介绍以及基本使用 这里不再说明. 关于多文件上传 以及上传文件的同时携带多个参数说明 网上涉及到的不是太多. 上一张帅图: 代码: apiService: /** params 参 ...

随机推荐

  1. JS错误记录 - To-do List

    var data = (localStorage.getItem('todolist'))? JSON.parse(localStorage.getItem('todolist')) : { todo ...

  2. vue.js提交按钮时简单的if判断表达式示例

    简单的业务需求如下,看图说话 1:当充值金额没有填写的时候,会有Toast小弹框提示"请输入有效的充值金额" if (!this.money) { console.log('mon ...

  3. percona-toolkit的安装及简单介绍

    MySQL数据库是轻量级.开源数据库的佼佼者.其功能和管理,健壮性与Oracle相比还是有相当的差距.因此有非常多功能强大第三方的衍生产品,如percona-toolkit,XtraBackup等等. ...

  4. drawable-图片绘制

    首先看一下,下端代码 private Bitmap createSelectedChip(RecipientEntry contact, TextPaint paint) { int height = ...

  5. 3.十分钟读懂——App开发规范的业务流程

    转自:http://www.itdaan.com/blog/2017/12/08/6bc06b3387a8d1238504355a6a1c6743.html 一.主要流程   二.产品立项 工作概述: ...

  6. [转]DOM0,DOM2,DOM3事件处理方式区别

    转 DOM0,DOM2,DOM3事件处理方式区别 2016年07月13日 15:00:29 judyge 阅读数:1457更多 个人分类: js与前端   引子:        文档对象模型是一种与编 ...

  7. [D3] Add image to the node

    We can create node with 'g' container, then append 'image' to the nodes. // Create container for the ...

  8. JS学习笔记 - 运动 - 淘宝轮播图

    <script> window.onload=function () { var oDiv=document.getElementById('play'); var aBtn=oDiv.g ...

  9. 手动删除RMAN备份的方法

    查询 RMAN> list backup; using target database control file instead of recovery catalog List of Back ...

  10. dinic算法学习(以poj1273为例)

    Dinic 算法模板  Dinic算法是一种比較easy实现的.相对照较快的最大流算法. 求最大流的本质,就是不停的寻找增广路径.直到找不到增广路径为止. 对于这个一般性的过程,Dinic算法的优化例 ...