- Sass 教程
- Sass — 首頁
- Sass — 概覽
- Sass — 安裝
- Sass — 語法
- 使用 Sass
- Sass — CSS 擴充套件
- Sass — 註釋
- Sass — 指令碼
- Sass — @ 規則和指令
- 控制指令和表示式
- Sass — 混合指令
- Sass — 函式指令
- Sass — 輸出樣式
- 擴充套件 Sass
- 有用的 Sass 資源
- Sass — 面試問題
- Sass — 快速指南
- 有用的 Sass 資源
- Sass — 討論
Sass — 布林運算
說明
你可以使用 and、or 和 not 運算子對 Sass 指令碼執行布林運算。
示例
以下示例展示了在 SCSS 檔案中使用布林運算的情況:-
<html>
<head>
<title>Boolean Operations</title>
<link rel = "stylesheet" type = "text/css" href = "style.css" />
<link rel = "stylesheet" href = "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src = "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
<body>
<h3>Example using Boolean Operations</h3>
<p class = "bool">SASS stands for Syntactically Awesome Stylesheet..</p>
</body>
</html>
接下來,建立檔案 style.scss。
style.scss
$age:20;
.bool {
@if ($age > 10 and $age < 25) {
color: green;
}
}
你可以使用以下命令告知 SASS 監聽該檔案,並在 SASS 檔案每次更改後更新 CSS:-
sass --watch C:\ruby\lib\sass\style.scss:style.css
下一步,執行以上命令,它將自動使用以下程式碼建立 style.css 檔案:-
style.css
.bool {
color: green;
}
輸出
讓我們執行以下步驟,瞭解以上給出的程式碼如何工作:-
將上述給定的 html 程式碼儲存在 boolean_operations.html 檔案中。
在瀏覽器中開啟此 HTML 檔案,將顯示一個輸出,如下所示。
sass_script.htm
廣告