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_

最新文章

  1. .NET正则表达式基础入门(一)
  2. python基础知识理解
  3. jq获取鼠标位置
  4. AngularJS Best Practices: ngRoute
  5. AWVS漏洞测试-03节-添加扫描项目
  6. Disable right click on the website
  7. poj 3013 Big Christmas Tree (最短路径Dijsktra) -- 第一次用优先队列写Dijsktra
  8. OLE操作Excel编译错误处理
  9. 微信SDK使用总结
  10. Connections between cities
  11. SPI、I2C、UART(转)
  12. Java NIO Channel通道
  13. centos6.5使用Google auth进行双因子认证
  14. Node.js(day6)
  15. [译]Ocelot - Logging
  16. ssm框架整合+Ajax异步验证
  17. 简单窗口与hbase数据库相连
  18. 解决wamp 3.0.6 访问路径出现 403 错误
  19. SSO后期补充理解
  20. Android-Service和Thread

热门文章

  1. Android JSON数据解析(GSON方式)
  2. 20160218.CCPP体系具体解释(0028天)
  3. [TS] Implement a singly linked list in TypeScript
  4. amazeui学习笔记二(进阶开发3)--HTML/CSS规范Rules
  5. 27. Spring Boot 部署与服务配置
  6. JPA的配置文件persistence.xml参数详解
  7. Mycat常见问题与解决方案---宜将剩勇追穷寇,不可沽名学霸王
  8. Js里面的arguments
  9. 如何安装Python环境以及为Visual Studio 2012安装Python插件
  10. softmax 与 sigmoid & softmax名字的由来