2024-07-12
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
Sass and SCSS are two syntaxes of Sass (Syntactically Awesome Stylesheets). They are both used to write more structured and maintainable CSS. The following are their main comparisons in syntax and features:
Sass (indented syntax)
{}
and semicolon;
。nav
ul
margin: 0
padding: 0
li
display: inline-block
margin-right: 5px
SCSS (Sassy CSS)
{}
and semicolon;
。nav {
ul {
margin: 0;
padding: 0;
}
li {
display: inline-block;
margin-right: 5px;
}
}
Both support variables, with the same syntax:
$primary-color: #333;
nav {
color: $primary-color;
}
Both support nesting, but in Sass, nesting uses indentation, while SCSS uses curly braces:
// Sass
nav
ul
margin: 0
padding: 0
// SCSS
nav {
ul {
margin: 0;
padding: 0;
}
}
The definition and invocation of the mixer is the same in both:
@mixin border-radius($radius) {
-webkit-border-radius: $radius;
-moz-border-radius: $radius;
-ms-border-radius: $radius;
border-radius: $radius;
}
.box { @include border-radius(10px); }
Interpolation is used the same way in both:
$side: left;
.margin-#{$side} {
margin-#{$side}: 10px;
}
Both support operations in styles:
.container {
width: 100% - 20px;
}
Both support style inheritance:
.message {
border: 1px solid #ccc;
padding: 10px;
color: #333;
}
.success {
@extend .message;
border-color: green;
}
.error {
@extend .message;
border-color: red;
}
Add them here next time you use them in a project!