You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- 1.6. [CSS Variables vs Preprocessor Variables](#16-css-variables-vs-preprocessor-variables) | [Difference Between CSS Variables and Preprocessor Variables](#16-difference-between-css-variables-and-preprocessor-variables)
64
65
65
66
1 Introduction to CSS Variables Custom Properties
66
67
=====================
@@ -521,7 +522,7 @@ ul > li {
521
522
1.5.1.2. Declaring a global / globally scoped CSS Variables - Convert above Green Theme to Blue Theme
522
523
---------------------
523
524
524
-
Its pretty easy to change the variable values once at central place and it simply modify the themes or base properties look/feel/appearance
525
+
It is pretty easy to change the variable values once at a central place and it simply modifies the themes or base properties look/feel/appearance
525
526
526
527
- To convert above metioned Green Theme into Blue Theme, just change: `--base-bg-color: #6696f9; --base-text-color: #37327b` and you are done.
527
528
@@ -638,7 +639,7 @@ ul > li {
638
639
---------------------
639
640
640
641
- We can also declare/create local variables, which are `accessible only to the declared element and it’s children`
641
-
- Local scoped CSS Variables are useful and make sense when we want to apply some properties and values only to specific part(s) of app
642
+
- Local scoped CSS Variables are useful and make sense when we want to apply some properties and values only to a specific part(s) of app
<figcaption> Image 1.5.2.1 - Styles Declaring & Using CSS Variables - Create local scoped variables </figcaption>
750
751
</figure>
751
752
</p>
753
+
754
+
1.6. CSS Variables vs Preprocessor Variables
755
+
---------------------
756
+
1.6. Difference Between CSS Variables and Preprocessor Variables
757
+
---------------------
758
+
759
+
Variables are one of the major reasons why CSS preprocessors like `SASS` or `LESS` introduced and exist at all in the web world. There are many differences between CSS Variables and Preprocessor Variables, some important differences are mentioned below:
| Browser understand CSS, so no need for compilation as we are working with pure/native CSS | We need to convert/compile .SASS, .SCSS and .LESS source files into .CSS every time, so that the browser can understand compiled .CSS code|
764
+
| More recently, native CSS has started supporting CSS variables, or "CSS Custom Properties". It allows you to work with variables directly in CSS. There are no compiling | Preprocessors introduced to use programming features like Variable, Functions, Loops into CSS styling, so Preprocessors source files must compile into .CSS |
765
+
| CSS variables are actually a part of the DOM | The variable was part of the preprocessor language (.SASS, .SCSS and .LESS files), not CSS itself. Once the code compiles, the variables are gone |
766
+
| CSS variables are always available and accessible while debugging with Inspect Element and one can easily change it from `Inspect -> Element -> Source`| The preprocessor code/variables would do nothing in a browser, The browser wouldn't understand the declarations and toss them out (.SASS, .SCSS and .LESS variables are not available in browser) |
767
+
| We can access and manipulate native CSS variables with JavaScript | As preprocessor uses (.SASS, .SCSS and .LESS) a separate file it is not accessible with JavaScript |
768
+
| One can easily access and overwrite CSS variables inside Media Query (as and when media or resolution changes the browser recheck/reassign/repaints the variable if needed | Sometimes it is not possible with preprocessor variables |
769
+
770
+
> **Note**: As Browser understands only CSS styling, the preprocessor code/variables would do nothing in a browser, The browser wouldn't understand the declarations and toss them out, that's the reason why Preprocessors files need to compile/converted into native CSS before sending/viewing into the browser
0 commit comments