Sass - 括號



介紹

括號是一對符號,通常用圓括號( )或方括號 [ ] 標記,提供影響運算順序的符號邏輯。

示例

以下示例演示了在 SCSS 檔案中使用括號 −

<html>
   <head>
      <title>String 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>
      <div class = "container">
         <h2>Example using Sass Parentheses</h2>
         <p>SASS stands for Syntactically Awesome Stylesheet..</p>
      </div>
   </body>
</html>

接下來,建立檔案 style.scss

style.scss

p {
   font-size:  5px + (6px * 2);
   color:#ff0000;
}

你可以透過使用以下命令,讓 SASS 監視該檔案,並在 SASS 檔案更改時隨時更新 CSS −

sass --watch C:\ruby\lib\sass\style.scss:style.css

接下來,執行上述命令;它將自動建立帶有以下程式碼的 style.css 檔案 −

style.css

p {
   font-size: 17px;
   color: #ff0000;
}

輸出

讓我們執行以下步驟,瞭解以上給定程式碼是如何工作的 −

  • 將上述給定的 html 程式碼儲存到 parentheses_example.html 檔案中。

  • 在瀏覽器中開啟此 HTML 檔案,輸出如下所示。

Sass Parantheses
sass_script.htm
廣告
© . All rights reserved.