[Sass] Level 4: Extend -- Ex
Better use @extend with % placeholder.
Extend is useful when you want to reuse some of you class. Always use % placeholder.
EXTEND I
It looks like .blueprint and .surveyor have a number of matching properties. Add an @extendto .surveyor to make this section more efficient.
.blueprint {
background: blue;
border-radius: 5px;
margin-bottom: 15px;
padding: 10px;
}
.surveyor {
background: blue;
border-radius: 5px;
color: #fff;
margin-bottom: 15px;
padding: 10px;
}
Answer:
.blueprint {
background: blue;
border-radius: 5px;
margin-bottom: 15px;
padding: 10px;
}
.surveyor {
@extend .blueprint;
color: #fff;
}
NESTED EXTEND
The developers are using .notice in some places of the application, .error in others, and are unable to only use one or the other. Extend the .notice styles into an .error declaration.
.notice {
background: yellow;
border: 5px solid #000;
padding: 20px;
&.alert {
background: red;
box-shadow: 0 0 10px red;
}
a {
color: #222;
&:hover {
color: #313131;
}
}
}
Answer:
.notice {
background: yellow;
border: 5px solid #000;
padding: 20px;
&.alert {
background: red;
box-shadow: 0 0 10px red;
}
a {
color: #222;
&:hover {
color: #313131;
}
}
}
.error {
@extend .notice;
}
EXTEND III
Some of the CSS copied over originally contains already-combined selectors. Refactor the segment below to make use of extend on .socket instead, in case we need to add elements later.
.socket,
.wrench,
.bolt {
border-radius: 50%;
padding: 15px;
width: 30px;
}
.wrench {
width: 100px;
}
.bolt {
padding: 14px;
}
Answer:
.socket {
border-radius: 50%;
padding: 15px;
width: 30px;
}
.wrench {
@extend .socket;
width: 100px;
}
.bolt {
@extend .socket;
padding: 14px;
}
PLACEHOLDER SELECTOR I
.group (commonly referred to as clearfix) is used throughout our application for clearing floats. To keep use of this relegated to our styles rather than allowing .group to be added as a class, convert .group over to a placeholder selector and update the extend inside .factory.
.group {
zoom:;
&:before,
&:after {
content: '';
display: table;
}
&:after {
clear: both;
}
}
.factory {
@extend .group;
background: #fff;
}
Answer:
%group {
zoom:;
&:before,
&:after {
content: '';
display: table;
}
&:after {
clear: both;
}
}
.factory {
@extend %group;
background: #fff;
}
PLACEHOLDER SELECTOR II
Whoops - we've discovered an alteration to .blueprint later in our stylesheet, and extending.blueprint with .surveyor is creating extra selectors in .factory that aren't needed. Create a placeholder selector called container to hold the shared properties and extend it with.blueprint and .surveyor to remove the extra .factory .surveyor selector.
.blueprint {
background: blue;
border-radius: 5px;
margin-bottom: 15px;
padding: 10px;
}
.surveyor {
@extend .blueprint;
color: #fff;
}
.factory {
background: #fff;
.blueprint {
margin-bottom: 20px;
}
}
Answer:
%container{
background: blue;
border-radius: 5px;
margin-bottom: 15px;
padding: 10px;
}
.blueprint {
@extend %container;
}
.surveyor {
@extend %container;
color: #fff;
}
.factory {
background: #fff;
.blueprint {
margin-bottom: 20px;
}
}
[Sass] Level 4: Extend -- Ex的更多相关文章
- sass的mixin,extend,placeholder,function
1. mixin 就是定义了一个函数,可以传参,并且设定默认值,css选择器可以通过@include来引用,mixin混入的代码,就是原样复制,不会合并,会造成冗余 例如: @mixin br6($b ...
- [Sass] Level 3: Mixin -- Ex
When to use MIXIN? Better way to use MIXIN is when you deal with browser prefiex, for example: @mixi ...
- SASS详解之沿袭(extend)
SASS详解之继承(extend) 每一个类名都有可能有另一个类名的所有样式和它自己的特定样式的.当一个div的身上有两个类名,一个是“one”,另一个是“two”的时候.如下 HTML代码 < ...
- CSS3与页面布局学习总结(七)——前端预处理技术(Less、Sass、CoffeeScript、TypeScript)
CSS不像其它高级语言一样支持算术运算.变量.流程控制与面向对象特性,所以CSS样式较多时会引起一些问题,如修改复杂,冗余,某些别的语言很简单的功能实现不了等.而javascript则是一种半面向对象 ...
- CSS3与页面布局学习笔记(七)——前端预处理技术(Less、Sass、CoffeeScript、TypeScript)
CSS不像其它高级语言一样支持算术运算.变量.流程控制与面向对象特性,所以CSS样式较多时会引起一些问题,如修改复杂,冗余,某些别的语言很简单的功能实现不了等.而javascript则是一种半面向对象 ...
- 关于前端CSS预处理器Sass的小知识!
前面的话 "CSS预处理器"(css preprocessor)的基本思想是,用一种专门的编程语言,进行网页样式设计,然后再编译成正常的CSS文件.SASS是一种CSS的开发工 ...
- SASS使用总结
简单用法: 变量 sass中可以定义变量,方便统一修改和维护. //sass style $fontStack: Helvetica, sans-serif; $primaryColor: #333; ...
- Sass@规则
@importSass 支持所有 CSS3 的 @ 规则, 以及一些 Sass 专属的规则,也被称为“指令(directives)”.Sass 扩展了 CSS 的 @import 规则,让它能够引入 ...
- Sass介绍及入门教程
Sass是什么? Sass是"Syntactically Awesome StyleSheets"的简称.那么他是什么?其实没有必要太过于纠结,只要知道他是“CSS预处理器”中的一 ...
随机推荐
- php最简单最基础入门笔记
偶然翻到之前刚学php时记录的笔记,特此分享给大家,希望对初学者有所帮助. php网页命名不支持中文 isset($abc) 判断变量是否被定义 empty($abc) 判断变量是否为空 u ...
- android 视频 2017
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha
- Java设计模式GOF之工厂模式
一.工厂模式(Factory) 1.实现了创建者和调用者的分离 2.应用场景 ①JDK中 Calendar 的 getInstance(): ②JDBC 的 Connection 对象的获取: ③Hi ...
- 用C读取系统明文(附源码)
从一好朋友那得到一个好东西 可以读取系统明文 请用vc++ 6.0编译 #include <windows.h> #include <stdio.h> // // Vsbat[ ...
- 2013年JavaScript开发人员调查结果
JavaScript开发人员调查现在已经结束,一如既往社区对结果进行了进一步分析: 总结(汉语) 原始数据(电子表格) 2012年结果 51%的被参与者写客户端代码,而28%的人说他们编写服务器端代码 ...
- jquery 图片预加载
/图片无序预加载 (function($){ function Preload(imgs,fns){ this.imgs=(typeof imgs==="string")?[img ...
- Centos安装Perforce
Author: JinDate: 20140827System: CentOS release 6.5 (Final) 参考:http://www.cnblogs.com/itech/archive/ ...
- ARM FPGA Extended Memory Interface
Connect a ARM Microcontroller to a FPGA using its Extended Memory Interface (EMI) http://elinux.org/ ...
- linux 内核大牛-谢宝友
http://blog.chinaunix.net/uid/25845340.html 谢宝友:毕业于四川省税务学校税收专业,现供职于中兴通讯操作系统团队,对操作系统内核有较强的兴趣.专职于操作系统内 ...
- C# 标签(条码)的打印与设计(二)
上一篇说到条码的打印,主要是通过读取模板定义文件(XML文件),然后结合从数据库中读取的动态数据结合而产生条码.下面主要说一下如何设计这个条码模板.设计过程也很简单,只需要简单的拖拉即可.然后点击小箭 ...