Sass — 布林運算



說明

你可以使用 andornot 運算子對 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 Boolean Operations
sass_script.htm
廣告
© . All rights reserved.