[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_
相关文章
- Android studio更新后出现警告:Warning:The `android.dexOptions.incremental` property is deprecated and it has
- The unit caddy.service has entered the 'failed' state with result 'exit-code'
- ORA-22978: only simple attribute name is allowed in the WITH OBJECT OID clause ORACLE 报错 故障修复 远程处理
- ORA-22980: must specify a set of attributes for the WITH OBJECT OID clause ORACLE 报错 故障修复 远程处理
- ORA-28071: The action is not valid. ORACLE 报错 故障修复 远程处理
- ORA-28074: The “string” field of the redaction parameters is not valid. ORACLE 报错 故障修复 远程处理
- ORA-30007: CONNECT BY ROOT operator is not supported in the START WITH or in the CONNECT BY condition ORACLE 报错 故障修复 远程处理
- ORA-31642: the following SQL statement fails: string ORACLE 报错 故障修复 远程处理
- ORA-41104: The database: string is the Cluster Director. ORACLE 报错 故障修复 远程处理
- ORA-48411: The trace files exceeds the maximum number [string] ORACLE 报错 故障修复 远程处理
- ORA-48464: The predicate buffer reached the maximum length [string] ORACLE 报错 故障修复 远程处理
- ORA-53253: The metadata for the new DICOM object is invalid. ORACLE 报错 故障修复 远程处理
- ORA-01664: Transaction which has expanded the Sort Segment has aborted ORACLE 报错 故障修复 远程处理
- ORA-06421: NETCMN: Error detected in the read-in data ORACLE 报错 故障修复 远程处理
- ORA-06814: TLI Driver: the SPX device file could not be opened ORACLE 报错 故障修复 远程处理
- ORA-13606: the specified task parameter element string is out of range for parameter string. ORACLE 报错 故障修复 远程处理
- ORA-13648: The specified execution type does not exist for this advisor. ORACLE 报错 故障修复 远程处理
- Oracle 00103: Redefining the Database Frontier(oracle00103)
- Oracle Database: Tackling the Complexities of Nulls(nulloracle)
- Unlocking the Hidden Secrets of Oracle Variables(oracle存在变量)
- 解决方法:给linux根目录挂载为读写权限。Explanation: To solve the issue of Linux root being readonly mount the root directory with readwrite permissions.(linux根只读)
- Coding with Linux: Enjoy the Benefits of an IDE(cidelinux)
- Linux Goes Global: The Growing Popularity of the Operating System Abroad(linux国外)
- Exploring the Powerful Union of MySQL: A Comprehensive Guide for Beginners(unionmysql)
- Mastering the Art of Linux with Complete Redirection Techniques(linux全部重定向)
- Exploring the Power of Grid Computing with Oracle: Optimizing Big Data Management(gridoracle)
- Boost Your File Transfer Efficiency with Linux Wput The Ultimate Tool for Uploading Large Files!(linuxwput)
- Exploring the Benefits and Challenges of Implementing a MySQL Multidatabase Architecture with Multiple Data Centers.(mysql多数据中心)
- Discover the Versatility of Tilda Linux: The Perfect Operating System for Tech Enthusiasts.(tildalinux)
- Exploring the Power of Linux with Vector Graphics(linux矢量)
- Mastering the Power of Alias in Linux: Simplify Your Workflow Today!(aliaslinux)
- Exploring the World of Video Editing with Linux: A Comprehensive Guide(视频linux)