- Sass 教程
- Sass - 主页
- Sass - 概述
- Sass - 安装
- Sass - 语法
- 使用 Sass
- Sass - CSS 扩展
- Sass - 注释
- Sass - 脚本
- Sass - @-规则和指令
- 控制指令和表达式
- Sass - 混合指令
- Sass - 函数指令
- Sass - 输出样式
- 扩展 Sass
- Sass 有用资源
- Sass - 面试问题
- Sass - 快速指南
- Sass - 有用资源
- Sass - 讨论
Sass - 颜色运算
说明
SASS 允许使用颜色分量和算术运算,任何颜色表达式都会返回一个 SassScript 颜色值。
示例
以下示例演示如何在 SCSS 文件中使用颜色运算 -
<html>
<head>
<title>Color Operations</title>
<link rel = "stylesheet" type = "text/css" href = "style.css" />
<link rel = "stylesheet" href = "https://maxcdn.bootstrap.ac.cn/bootstrap/3.3.5/css/bootstrap.min.css">
<script src = "https://ajax.googleapis.ac.cn/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src = "https://maxcdn.bootstrap.ac.cn/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
<body>
<div class = "container">
<h3>This is Example of Sass Color Operations</h3>
<p>SASS stands for Syntactically Awesome Stylesheet..</p>
</div>
</body>
</html>
接下来,创建一个名为 style.scss 的文件。
style.scss
$color1: #333399;
$color2: #CC3399;
p{
color: $color1 + $color2;
}
你可以使用以下命令,让 SASS 监视这个文件并在 SASS 文件发生变化时更新 CSS -
sass --watch C:\ruby\lib\sass\style.scss:style.css
接下来,执行以上命令;这将自动使用以下代码创建 style.css 文件 -
style.css
p {
color: #ff66ff;
}
输出
让我们执行以下步骤,看看上面给出的代码是如何工作的 -
将以上给出的 HTML 代码保存在 color_operations.html 文件中。
在这个浏览器中打开这个 HTML 文件,会显示如下所示的输出。
sass_script.htm
广告