[SCSS] Use Standard Built-in SCSS Functions for Common Operations

We can use javascript for color and opacity variations, math, list and map logic or to see if something exists. SCSS includes functions for a wide range of common use cases for logic in our styles. In this lesson we look at some of the more useful color functions to improve development velocity, readability, and simplify the code. Be sure to checkout all the SCSS functions: http://sass-lang.com/documentation/Sass/Script/Functions.html

 

复制代码
$base: #24ea12;
$lighten_base: lighten($base, 25%);
$darken_base: darken($base, 25%);

$clb: complement($base);
$cllb: complement($lighten_base);
$cldb: complement($darken_base);

$light-color: scale_color($base, $alpha: -50%);
$dark-color: scale_color($base, $saturation: -35%);

.base {
  background-color: $base;
  color: $clb;
}

.lighten_base {
  background-color: $lighten_base;
  color: $cllb;
}

.darken_base {
  background-color: $darken_base;
  color: $cldb;
}

.linear-gradient {
  background-image: linear-gradient($clb, $cllb, $cldb);
  color: mix($base, yellow, 25%);
}


.hover {
  background-image: linear-gradient($base, $lighten_base, $darken_base);
  color: mix($base, yellow, 25%);
  &:hover {
    color: transparentize(mix($base, yellow, 25%), .5); // based on given color, add 0.5 opacity
  }
}

.darken-color {
  color: $dark-color;
}

.lighten-color {
  color: $light-color;
}






.container {
  display: grid;
  grid-gap: 10px;
  grid-template-columns: 1fr 1fr 1fr;
  counter-reset: box;
  height: 100vh;
}

.box:before {
  counter-increment: box;
  font-size: 3em;
  content: counter(box);
}

.box {
  display: flex;
  justify-content: center;
  align-content: center;
  align-items: center;
}
复制代码

 

Github

posted @   Zhentiw  阅读(234)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
点击右上角即可分享
微信分享提示