Created by
Less
, SASS
, Stylus
, PostCSS
Sass is the most mature, stable, and powerful professional grade CSS extension language in the world.
scss
and indented
syntax. But more on that - latterDart Sass
-g
option) then there is no matter in which folder you execute the given command
npm install -g sass
style.scss
$color : #F100FF;
$bg_color : #5C5454;
.test{
color: $color;
background: $bg_color;
}
Command Palette=>Live Sass: Watch Sass
watch mode
will make Sass compiler to watch for changes in your Sass file and compile to CSS on each change automatically.style.css
should be created in the current folderstyle.scss
file lives.
$ sass sass_demo.scss sass_demo.css
--watch
filessass
to --watch your file or directory for changes and to compile automatically on each change
$ sass --watch sass_demo.scss sass_demo.css
--watch
folder
├── app
│ └── scss
│ └── sass_demo.scss
├── dist
│ └── styles
└── sass_demo.html
$ sass --watch app/scss:dist/styles
>Compiled app/scss/sass_demo.scss to dist/styles/sass_demo.css.
>Sass is watching for changes. Press Ctrl-C to stop.
{
"liveSassCompile.settings.formats": [
{
"format": "expanded",
"extensionName": ".css",
// / -> denotes relative to the workspace root
"savePath": "/dist/css",
},
{
"format": "compressed",
"extensionName": ".min.css",
// / -> denotes relative to the workspace root
"savePath": "/dist/css"
},
],
"liveSassCompile.settings.generateMap":false,
}
.sass
.scss
$
and its value is assigned like a CSS value to a property. I.e. with the column notation.
// declare to variables:
$fg-color: #F100FF;
$bg-color: #952b2b;
// and use it, like that:
.test{
color: $fg-color;
background: $bg-color;
}
$fs-normal:16px;
.test{
<!-- string literal value -->
color: red;
<!-- expression value -->
font-size: $fs-normal + 2px;
}
.test {
color: red;
font-size: 18px;
}
// numbers
$number: 1.23;
// strings (can be quoted or unquoted)
$foo:"bar";
$foo:bar;
// colors:
$color:red;
$color:#F00;
$color:rgba(255,0,0,0.5);
// boolean
$shown:true;
$shown:false;
// null:
$test:null;
// lists (any expression, separated with spaces or commas )
$border: 1px solid $color;
$font: "Helvetica", serif;
//maps (like dictionary)
$color_map: (
light: #ccc,
dark: #000
);
$box_width:200px;
$box_height:$box_width*2;
.parent{
width: $box_width;
height: $box_height;
background-color: red;
div{
width: $box_width/2;
height: $box_height/2;
background-color: blue;
}
}
.parent {
width: 200px;
height: 400px;
background-color: red;
}
.parent div {
width: 100px;
height: 200px;
background-color: blue;
}
$rounded: null;
.button {
border: 1px solid #999;
border-radius: $rounded;
}
.button {
border: 1px solid black;
}
.A{
/* A declarations */
.B{
/* B declarations */
}
}
.A{
/* A declarations */
}
.A .B{
/* B declarations */
}
&
&
symbol. Like in
a{
text-decoration: none;
&:hover{
text-decoration: underline;
}
}
a {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
&
&:
a{
text-decoration: none;
&:hover{
text-decoration: underline;
&:after{
content: ">>";
}
}
}
a {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
a:hover:after {
content: ">>";
}
&
&
should be at the beginning of the selector, but it can be followed by a suffix that will be added to the parent selector
.btn{
background: gray;
border-radius: 20%;
&-alert{
background: red;
}
}
.btn {
background: gray;
border-radius: 20%;
}
.btn-alert {
background: red;
}
.cover{
background:{
image:"img1.png";
size: 100% 100%;
position: center;
}
}
.cover {
background-image: "img1.png";
background-size: 100% 100%;
background-position: center;
}
TODO: update for @use (https://sass-lang.com/documentation/at-rules/import), i.e. modules.
_variables.scss
.@import "file_name"
, where file_name
is the name of the partial without underscore. You can skip the ".scss" extension
$box_width:200px;
$box_height:200px;
@import "global_variables";
See the Pen SCSS demo by Iva Popova (@webdesigncourse) on CodePen.
These slides are based on
customised version of
framework