SASS
Called the CSS preprocessor, his basic idea is to use a specialized programming language for page style design, and then compile into a normal CSS file.
The use of SASS
Installation
Sass is written in Ruby, so we need to install Ruby (Ruby installs itself Baidu) before installing SASS, and execute the following command to install:
gem install sass
Use
Sass is an ordinary text file with a suffix called. Scss. Then, after we have written the file in SASS syntax, we need to compile the. css file to be used by the HTML file (that is, by introducing the HTML file via the link tag), then we can use the command line or the Git tool to enter:
sass test.scss test.css #假设我们的sass文件名为test
Here is an example of a specific compilation sass:
First we build such two files in a folder:. html,. scss
Then write the code in each of the two files:
<!-- html --><!DOCTYPE html>
Then we compile the SCSS code into. CSS code with git, and we get the following three files, one of which is the. css file we need.
Running HTML will give you the following results.
Sass Grammar Basics
Variable
Sass is the concept of a variable, so the variables begin with $ .
$blue:red;div{ color:$blue;}
If the variables need to be embedded in the string, we have to put them in #{} .
$side : right; .rounded { border-#{$side}-radius: 5px; }
Calculation function
SASS allows you to use a calculation in your code:
$var:40;body { margin: (14px/2); top: 50px + 100px; right: $var * 10%;}
Nesting
is our div and tag box can be nested set CSS
div { p { color:red; }}
Attributes can also be nested: Border-color
Border must be appended with a colon
div { p { border: { color: red; } }}
Within a nested code block, you can use & to refer to the parent element, such as: a:hover Pseudo-class, which can be written as:
a { &:hover { color: #ffb3ff; }}
Comments
Same as CSS file comments/* Comment */.
CondCSS preprocessor sass Getting started learning