Sass can help us reduce repetitive code in CSS and save development time.
We can install different properties to create some code files, such as variable definition files, color-related files, font-related files, and so on. Similar to CSS,Sass support CSS Sass the Note: there is no need to specify a file suffix when including a file. Sass will automatically add a suffix In addition, you can also import CSS files. After import, we can use variables such as import files in the main file. For the following example, import Next, let’s create a And then we’re here. Convert the above code to CSS code, as follows: If you don’t want to compile a Sass code file into a CSS file, you can add an underscore at the beginning of the file name. This will tell Sass not to compile it into a CSS file. However, we do not need to add an underscore in the import statement. Sass Partials syntax format: The following example creates a If you are importing the file, you do not need to use an underscore: Note: please do not put underlined and ununderlined files of the same name in the same directory, such as 13.5.1. Sass Import Fil ¶
@import
instructions.
@import
directive allows us to import other files and so on.
@import
each time the instruction is called, an additional HTTP request is created. But, Sass,
@import
directive to include the file inthe CSS and no additional HTTP requests are required.
@import
instruction syntax is as follows:@import filename;
.scss
.
variables.scss
、
colors.scss
and
reset.scss
files.Sass Code: ¶
@import "variables";
@import "colors";
@import "reset";
reset.scss
file:
reset.scss
file code: ¶ html,
body,
ul,
ol {
margin: 0;
padding: 0;
}
standard.scss
used in the file
@import
instruction import
reset.scss
file:
standard.scss
file code: ¶ @import "reset";
body {
font-family: Helvetica, sans-serif;
font-size: 18px;
color: red;
}
Css Code: ¶
html, body, ul, ol {
margin: 0;
padding: 0;
}
body {
font-family: Helvetica, sans-serif;
font-size: 18px;
color: red;
}
13.5.2. Sass Partials ¶
_filename;
\_colors.scss
, but will not be compiledinto
\_colors.css
file:
\_colors.scss
file code: ¶ $myPink: #EE82EE;
$myBlue: #4169E1;
$myGreen: #8FBC8F;
Example ¶
@import "colors";
body {
font-family: Helvetica, sans-serif;
font-size: 18px;
color: $myBlue;
}
_colors.scss
and
colors.scss
cannotexist in the same directory at the same time, otherwise underlined files will be ignored.