[SCSS] Write Custom Functions with the SCSS @function Directive
Writing SCSS @functions is similar to writing functions in other programming languages; they can accept arguments and have return statements. SCSS provides a ton of great features, but sometimes we need to roll our own function. We can do that too! They’re useful when the desired functionality isn’t available from the built in SCSS functions and a mixin just won’t do. In this lesson, we learn how and when to use SCSS function directives.
@function font-scale($exponent, $base-font-size: 14px, $ratio: 1.2) {
$value:;
@for $i from 1 through $exponent {
$value: $value * $ratio;
@debug $value;
}
@return if($exponent > 0, $base-font-size * $value, $base-font-size);
}
.stuff { font-size: font-scale(4); }
.things { font-size: font-scale(2); }
@for $i from 1 through 6 {
$exponent: 7 - $i;
h#{$i} { font-size: font-scale($exponent, $ratio: 1.5); }
}
Notice, we using '@debug' directive, it can help to print out the value in console
We get:
.stuff {
font-size: 29.0304px; }
.things {
font-size: 20.16px; }
h1 {
font-size: 159.46875px; }
h2 {
font-size: 106.3125px; }
h3 {
font-size: 70.875px; }
h4 {
font-size: 47.25px; }
h5 {
font-size: 31.5px; }
h6 {
font-size: 21px; }
[SCSS] Write Custom Functions with the SCSS @function Directive的更多相关文章
- [翻译] Using Custom Functions in a Report 在报表中使用自己义函数
Using Custom Functions in a Report 在报表中使用自己义函数 FastReport has a large number of built-in standard ...
- Adding New Functions to MySQL(User-Defined Function Interface UDF、Native Function)
catalog . How to Add New Functions to MySQL . Features of the User-Defined Function Interface . User ...
- SQL Fundamentals || Single-Row Functions || 转换函数 Conversion function
SQL Fundamentals || Oracle SQL语言 SQL Fundamentals: Using Single-Row Functions to Customize Output使 ...
- graphite custom functions
尊重作者的劳动,转载请注明作者及原文地址 http://www.cnblogs.com/txwsqk/p/6522854.html 参考 https://graphite.readthedocs.io ...
- vue,一路走来(17)--vue使用scss,并且全局引入公共scss样式
最近朋友问如何在vue项目中使用scss样式,想起之前项目是直接在main.js直接import css文件的,然而main.js不可以直接import scss文件. import './asset ...
- Functions that return a function
javascript学习中,经常会遇到闭包的问题,然后闭包的很多例子中又会遇到很多返回函数的闭包的例子程序.因为对闭包的理解还不够透彻,然后对于Functions rerurn a function产 ...
- [SCSS] Loop Over Data with the SCSS @each Control Directive
The SCSS @for directive is great when we know how many iterations are required and we only need 1 va ...
- [SCSS] Write similar classes with the SCSS @for Control Directive
Writing similar classes with minor variations, like utility classes, can be a pain to write and upda ...
- 在vue-cli中安装scss,且可以全局引入scss的步骤
简历魔板__个人简历模板在线生成 在写vue的css样式时,觉得需要css预处理器让自己的css更加简洁.适应性更强.可读性更佳,更易于代码的维护,于是在vue-cli脚手架采用scss.写过的人都知 ...
随机推荐
- 9.使用 npm 命令安装模块
转自:http://www.runoob.com/nodejs/nodejs-tutorial.html npm 安装 Node.js 模块语法格式如下: $ npm install <Modu ...
- Spring源码分析专题 —— IOC容器启动过程(上篇)
声明 1.建议先阅读<Spring源码分析专题 -- 阅读指引> 2.强烈建议阅读过程中要参照调用过程图,每篇都有其对应的调用过程图 3.写文不易,转载请标明出处 前言 关于 IOC 容器 ...
- [NOI2008]假面舞会(DFS)
Description 一年一度的假面舞会又开始了,栋栋也兴致勃勃的参加了今年的舞会.今年的面具都是主办方特别定制的.每个参加舞会的人都可以在入场时选择一 个自己喜欢的面具.每个面具都有一个编号,主办 ...
- 【Codeforces Round #452 (Div. 2) C】 Dividing the numbers
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] n为偶数. l = 1, r = n (l,r)放在一组 l++,r-- 新的l,r放在另外一组 直到l+1==r 这个时候,判断两 ...
- 2.Web开发过程流程图
转自:https://blog.csdn.net/hello_simon/article/details/19993343 最近公司在进行一系列新模块的开发,在痛苦开发的过程中,大家不时在一起进行总结 ...
- JQuery 各节点获取函数:父节点,子节点,兄弟节点
jQuery.parent(expr) //找父元素 jQuery.parents(expr) //找到所有祖先元素,不限于父元素 jQuery.children ...
- ajax 通过return 返回data值
方法例如以下: 1. ajax 必须为同步 设置async:false 2. 定一个局部变量 把data赋值给局部变量 然后 return 局部变量就可以 示比例如以下 function getEmp ...
- 将html转换为word文档的几种方式
1 基于wps直接将页面信息下载成word文档 public void test() { WPS.Application wps = null; try { wps = new WPS.Applica ...
- Redis学习笔记(六)---List
1.ArrayList与LinkList的区别 ArrayList的使用数组存入的方式,所以根据索引查询数据速度快,而增删元素是比较慢的,它需要将数据一位一位的移动,知道达到要求. LinkList使 ...
- docker基础(二)
1.base镜像的特点 (1)不依赖于其他的镜像 (2)其它的可以通过它位基础作为容器的底层 2.在下载镜像的时候,只有几百M,但是安装一个Ubuntu虚拟机的镜像就比较大,首先会想到图形化界面,其实 ...