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. DG查看恢复进度

    查看恢复进度 (1)查看进程的活动状态 V$MANAGED_STANDBY视图专用于显示物理Standby数据库相关进程的当前状态,该视图中的列也很有特点,查看进程状态时,通常我们会关注PROCESS ...

  2. 洛谷 P1032 字符变换

    洛谷 P1032 字符变换 题目描述 已知有两个字串 A,B 及一组字串变换的规则(至多 6 个规则): A1​ -> B1​ A2​ -> B2​ 规则的含义为:在 A 中的子串 A1​ ...

  3. [TS] Parse a string to an integer

    A common interview question is to write
 a
function
that
converts
 a
 string
into
an
integer e.g. &q ...

  4. hello word-python 入门

    今天正式开始学习python,先写一个最今经典的例子 helloword #!/usr/bin/python3.2 print("hello work!") 知识点: #!usr/ ...

  5. .condarc(conda 配置文件)

    Configuration - Conda documentation .condarc以点开头,一般表示 conda 应用程序的配置文件,在用户的家目录(windows:C:\\users\\use ...

  6. .net core 时间格式转换

    //string time = "2019-01-18 13:50:38"; string time = "2019-01-18 13:50:38 256"; ...

  7. Codeforces Round #445 Div. 1 C Maximum Element (dp + 组合数学)

    题目链接: http://codeforces.com/contest/889/problem/C 题意: 给你 \(n\)和 \(k\). 让你找一种全排列长度为\(n\)的 \(p\),满足存在下 ...

  8. TCP超时重传机制

    TCP协议在能够发送数据之前就建立起了"连接".要实现这个连接,启动TCP连接的那一方首先将发送一个SYN数据包.这只是一个不包含数据的数据包, 然后,打开SYN标记.如果另一方同 ...

  9. 软件——关于C,typedef

    1;;写博客能让我慢下来,仔细思考 1;;这篇博客大多摘自网上 1;; 不管实在C还是C++代码中,typedef这个词都不少见,当然出现频率较高的还是在C代码中.typedef与#define有些相 ...

  10. Nginx TCP代理

    nginx 在1.9.0 版本发布以前如果要想做到基于TCP的代理及负载均衡需要通过打名为nginx_tcp_proxy_module的第三方patch来实现,该模块的代码托管在github上 网址: ...