What Is Scss And How To Use Scss In Html ? 2021
What Is Scss And How To Use Scss In Html ? 2021
CSS stands for Sassy Cascading Style Sheets and it’s an extension of CSS which adds nested rules Variables, mixin, selector, inheritance, and a lot more features. Now Scss is written in Ruby and it’s intended to make our lives a lot easier in writing CSS.
CSS Or SCSS – Which Is Better?
CSS is the styling language that is used to style web pages and it is understandable by the browser. Using SCSS, we can add any additional functionality to CSS such as nesting, mixin, variables, and more. All these additional functionalities can make writing CSS much easier and faster as compared to writing the traditional CSS. SCSS produces a traditional CSS that the browser can understand by running the SCSS files on the server running your web app.
- best free android backup software for pc
- hair color change app
- trustworthy rom sites
- free animations download for websites
- could not find module “@angular-devkit/build-angular”
- npm: command not found
- prevnext
- sites like codepen
HOW TO USE SCSS
HOW SCSS WORKS?
Advantages Of Using SCSS?
SCSS is more expressive
We can compress several lines of code in SASS syntax into much less number of lines of SCSS. In SCSS, the standard lines can also be compressed when I’m doing something complicated and can be expanded again for reference.
SCSS allows the user to write better inline documentation
SASS is flexible with comments, but any good developer will prefer inline documentation which is available in SCSS. Inline documentation makes the lines of code self-explanatory.
It encourages proper nesting of rules
If you use the comma operator at a high level, it increases the file size of the final CSS. This can result in making the code really hard to perform overriding of rules.
Integrating existing CSS tools and CSS codebase is much easier
Syntax highlighting widely used CSS tool and is supported in SCSS. SCSS allows you use the existing code, and help improve its internal structure without altering the external behavior of the code.
Compile Scss To Css By Npm
- create a folder of scss and then create a file that should be style.scss
- create a folder of CSS and then create a file that should be style.css
- Then use this cmd.
cmd
1
|
sass —watch sass/style.scss:css/style.css
|
Best Tools To Compile SCSS
- VS Code
- Scout-App (MAC, Windows, Linux)- Free
- Prepros (MAC, Windows, Linux)-Paid
- Koala (MAC, Windows, Linux) – Free
- Compass
- Hammer (MAC)-Paid
CODE OF SYNTAX
SASS includes two types of syntax such as SCSS (sassy CSS) is called the compliant of CSS which uses.scss as extensions
Indented (simply called sass) it uses. Sass as its extension, it is not compliant to CSS but they are indentation rather than brackets. It is quick to write the code.
VARIABLES
It would reuse and to do this with Scss where we’re going to use a dollar symbol to make something a variable so here’s an example where we have a variable called control height set to 40 pixels and we use that variable for a header class and a subheader class now if we were to write this in CSS we would simply write the number itself in this case we’re only using it for two classes but in long style sheets where we use multiple 50 to 100 classes.
CODE OF SYNTAX
SASS includes two types of syntax such as SCSS (sassy CSS) is called the compliant of CSS which uses.scss as extensions
Indented (simply called sass) it uses. Sass as its extension, it is not compliant to CSS but they are indentation rather than brackets. It is quick to write the code.
VARIABLES
1
2
|
$red: #FF0000;
body { color:$red; }
|
MIXINS
So let’s take a look at an example here to create a mixin we’re going to use the add sign directive and give it a name so we have a mixin here called awesomely and we included in two different elements one called the body and one is a paragraph so that awesome mixin can have probably or how many other declarations it might want maybe want to put a border or maybe a radius or a font color and it can insert those properties into different elements as well so it’s very useful and this would translate like this and CSS where it’s a little bit more declarative and we have to specify the width and the height for each element.
MIXINS
1
2
3
|
@mixin reset–list {
margin: 0; padding: 0; list–style: none;
}
|
1
|
nav ul { @include reset–list; }
|
NESTING
Nesting is a good method of reducing the code in sword braces. The amount of code you write will be reduced in Nesting. If it could not be able to execute carefully it will be termed as over-qualified CSS.
The main reason to nest the CSS Selector is to imitate your HTML hierarchy. Nesting is a good method of reducing the code in sword braces. The amount of code you write will be reduced in Nesting.
If it could not be able to execute carefully it will be termed as over-qualified CSS. The main reason to nest the CSS Selector is to imitate your HTML hierarchy.
1
2
3
4
5
|
ul{
li{
a{ padding: .25em; line–height: 0;}
}
}
|
Prefixing Parent Selector References
This is the familiar way you’re probably using &
:
1
|
a { &:hover { color: red; } }
|
1
2
|
/* compiled CSS */
a:hover { color: red; }
|
&
can be used with a prefix just as well:
1
2
3
4
5
|
p { body.no–touch
& { display: none;
// hide the message if not on a touch device
}
}
|
1
2
|
/* compiled CSS */
body.no–touch p { display: none; }
|
This can be very useful when you have a deep nesting of rules, and you want to effect a change to the styling of an element based on a selector match much closer to the DOM root.
EXTENDED /INHERITANCE
1
2
|
.error { border: 1px #f00; background-color: #fdd; }
p{ @extend .error; border–width: 3px; }
|
Placeholder Selectors
Because in the above example(s) the .animal
the base class isn’t used anywhere directly (only through its child classes), we might just as well get rid of it in the CSS output. SCSS allows this with placeholder selectors. Whereas .foo
signifies a class, and #foo
an ID, %foo
is considered a placeholder, and gets special treatment by the compiler: its styles are never output on their own, only through extension.
1
2
3
4
5
6
7
8
9
10
11
12
13
|
%animal {
background: gray;
// and so on…
}
.cat {
@extend %animal;
color: white;
}
.dog {
@extend %animal;
color: black;
}
|
1
2
3
4
5
6
7
8
9
10
|
/* compiled CSS */
.cat, .dog {
background: gray;
}
.cat {
color: white;
}
.dog {
color: black;
}
|
OPERATORS
IMPORT
1
|
@import ‘extra’‘;
|
PARTIALS