[SCSS] Reuse Styles with the SCSS @extend Directive
We can write reusable styles with the SCSS @extend or @mixin directives. Which one is better? It depends. A better question is, how do they differ?
Extends:
change the source order, mixins don’t.
maintain relationships, mixins don’t.
share inherited traits, mixins don’t.
can extend multiple classes, mixins don’t.
can create multiple class declarations in the compiled CSS, mixins don’t.
can use the placeholder selector, mixins don’t.
Mixins:
can accept arguments, extends don’t.
can pass additional content, extends don’t.
repeat code when compiled, extends group class names together.
work well wIth media queries, extends have a limited interaction wIth media queries.
In this lesson we learn about writing reusable styles with the @extend directive and how it compares to the @mixin directive.
.base {
color: red; &:hover {color: green}
&::after {content: "?"} &-stuff {height: 5rem} // this will not be extended
} .cool {height: 20rem} .new {
width: 20px;
// extend multi classes
@extend .base, .cool;
} /*
It is possible to use placeholder
*/ %base {
color: red;
} .new2 {
@extend %base;
} /*
Placeholder for extend with mixin
*/
%hero {background: linear-gradient(red, white, black)}
%villain {background: darkred} @mixin character($type: hero) {
height: 20px;
width: 20px; @extend %#{$type} // #{} --> output a string
} .doc-ock {@include character(villain)} /*
Works with media query
*/
@media screen and (min-width: 800px) {
%buddy { color: purple; }
} @media screen and (min-width: 800px) {
.buddy {
@extend %buddy;
}
}
Reference to http://sass-lang.com/documentation/file.SASS_REFERENCE.html#interpolation_
[SCSS] Reuse Styles with the SCSS @extend Directive的更多相关文章
- [SCSS] Reuse Styles with the SCSS @mixin Directive
Copy/pasting the same code is redundant and updating copy/pasted code slows development velocity. Mi ...
- 在vue-cli中如何安装scss,并全局引入scss
在vue-cli脚手架采用scss正确的使用姿势 步骤一: 安装node-sass.sass-loader.style-loader npm install node-sass --save-dev ...
- [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 ...
- error app/styles/components/iconfont.scss (Line 12: Invalid GBK character "\xE5")
因为要用到iconfont,引入iconfont到sass文件后,出现编译sass文件错误,如下截图: 解决方法:在顶部设置编码格式 @charset "utf-8"; 编译成功!
- 在vue项目中使用scss,以及vscode适配scss语法(解决使用scss语法编辑器报错)
项目搭建好之后 安装sass 依赖包 npm install --save-dev sass-loader //sass-loader依赖于node-sass npm install --save-d ...
- dvaJs使用注意事项
项目参考地址 dva-yicha 1. 使用路由跳转的方式 (1)所有的路由跳转功能都放到 dva/router 里面的 import { routerRedux } from 'dva/router ...
- css预编译语言 sass scss(变量$var, css嵌套规则,@import规则,@extend,@mixin)
什么是sass Sass 是对 CSS 的扩展,让 CSS 语言更强大.优雅. 它允许你使用变量.嵌套规则. mixins.导入等众多功能, 并且完全兼容 CSS 语法. Sass 有助于保持大型样式 ...
- Scss开发临时学习过程
SCSS语法: 假设变量申明带有!default,那么如果在此申明之前没有这个变量的申明,则用这个值,反之如果之前有申明,则用申明的值. ‘...’传递多个参数: @mixin box-shadow( ...
- 前端之Sass/Scss实战笔记
简介 Sass 有两种语法规则(syntaxes),目前新的语法规则(从 Sass 3开始)被称为 “SCSS”( 时髦的css(Sassy CSS)),它是css3语法的的拓展级,就是说每一个语法正 ...
随机推荐
- Linux下SPI读写外部寄存器的操作
SPI写寄存器操作: staticvoid mcp251x_write_reg(struct spi_device *spi, uint8_t reg, uint8_t val) { stru ...
- 26.event跨进程通信
以id创建事件 ] = "myevent"; HANDLE event = CreateEventA(NULL, FALSE, FALSE, name); 设置事件 SetEven ...
- 2.3 Streams API 官网剖析(博主推荐)
不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ 2.3 Streams API 2.3 Streams API 在0..0增加了一个 ...
- http 协议上传文件multipart form-data boundary 说明--转载
原文地址:http://xixinfei.iteye.com/blog/2002017 含义 ENCTYPE="multipart/form-data" 说明: 通过 http 协 ...
- 升级你的Linux日志系统
650) this.width=650;" onclick='window.open("http://blog.51cto.com/viewpic.php?refimg=" ...
- weblogic虚拟路径配置
首发地址 https://blog.leapmie.com/archives/344/ 前言 weblogic的虚拟路径配置有两种: 一种是在项目下配置,即在weblogic.xml中配置,该方法配置 ...
- 给VG增加磁盘,给文件目录增加空间
一: #lspv 找到新增加的物理卷(逻辑驱动器,以hdisk8为例). #chdev –l hdisk8 –a pv=yes写入新的物理卷的pvid. #extendvg cwdatavg hdis ...
- python学习一,python基本语法
python基本语法: 1.python基本语句结构: 首先,在其他的语言中,比如java,c++,c#等,没写完一行语句之后,都需要在语句的末尾加一个分号,表示该语句结束,但是在python中,我们 ...
- listview-属性大全
<ListView <!-- 决定listview里的内容是否从底部开始 -- android:stackFromBottom="true" </Listview ...
- JS 数字格式千分位相互转换
/** * 将数值四舍五入后格式化. * * @param num 数值(Number或者String) * @param cent 要保留的小数位(Number) * @param isThousa ...