@if expression { //CSS codes are written here }
<html> <head> <meta charset="utf-8"> <title>控制指令和表達式</title> <link rel="stylesheet" type="text/css" href="style.css"/> </head> <body> <div class="container"> <h2>Example for Control Directive & Expressions</h2> <p>SASS stands for Syntactically Awesome Stylesheet. </p> </div> </body> </html>
p{
@if 10 + 10 == 20 { border: 1px dotted; }
@if 7 < 2 { border: 2px solid; }
@if null { border: 3px double; }
}
sass --watch C:\Ruby22-x64\style.scss:style.css
p {
border: 1px dotted; }
在瀏覽器中打開該HTML文件,獲取輸出如下顯示