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; }

最新文章

  1. 位置指纹(LF)定位技术简介-室内定位
  2. 第三个Sprint冲刺github 与最终 github
  3. FNV哈希算法
  4. Aspectj是什么
  5. SQL的内连接与外连接
  6. java四种数组排序
  7. 假设用一个名为text的字符串向量存放文本文件的数据,其中的元素或者是一句话或者是一个用于表示段分隔的空字符串。将text中第一段全改为大写形式
  8. 可否控制<link type=text/css rel=stylesheet href=style.css>
  9. Solr与Tomcat的整合
  10. POJ1062 昂贵的聘礼(最短路)
  11. windows 编程 —— 消息与参数(滚动条、键盘、鼠标)
  12. AttributeError at /home/home/ Exception Type: AttributeError at /home/home/
  13. nagios总结
  14. C#图解第七章:类和继承
  15. vue 动态创建组件(运行时创建组件)
  16. 手把手教你用 Git(转)
  17. linux服务器设置只允许密钥登陆
  18. ThreadLocal解决SimpleDateFormat多线程安全问题中遇到的困惑
  19. php银行卡校验
  20. [leetcode]N-Queens II @ Python

热门文章

  1. A. Keyboard Codeforces Round #271(div2)
  2. chrome模拟手机功能
  3. php课程 18-60 cookie和session的最主要区别是什么
  4. jQuery post 打开新窗口
  5. golang filepath.Glob
  6. angular 子组件与父组件通讯
  7. CISP/CISA 每日一题 19
  8. 1、DOM4J简介
  9. C 字符/字符串经常使用函数
  10. JS截取字符串 charAt(),slice(),substring(),substr()