File tree Expand file tree Collapse file tree 2 files changed +42
-1
lines changed Expand file tree Collapse file tree 2 files changed +42
-1
lines changed Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ and pairing with smart people at Hashrocket.
99
1010For a steady stream of TILs, [ sign up for my newsletter] ( https://tinyletter.com/jbranchaud ) .
1111
12- _ 894 TILs and counting..._
12+ _ 895 TILs and counting..._
1313
1414---
1515
@@ -102,6 +102,7 @@ _894 TILs and counting..._
102102- [ Clean Up Repetition With : is () Pseudo-Class] ( css/clean-up-repetition-with-is-pseudo-class.md )
103103- [ Conditional Styling For Unsupported CSS Features] ( css/conditional-styling-for-unsupported-css-features.md )
104104- [ Create A Pulsing Background With CSS Animation] ( css/create-a-pulsing-background-with-css-animation.md )
105+ - [ Define CSS Custom Properties With CSS Variables] ( css/define-css-custom-properties-with-scss-variables.md )
105106- [ Dry Up SCSS With Mixins] ( css/dry-up-scss-with-mixins.md )
106107- [ Give Elements The Same Width With Flexbox] ( css/give-elements-the-same-width-with-flexbox.md )
107108- [ Lighten And Darken With CSS Brightness Filter] ( css/lighten-and-darken-with-css-brightness-filter.md )
Original file line number Diff line number Diff line change 1+ # Define CSS Custom Properties With SCSS Variables
2+
3+ It doesn't work to directly declare a CSS custom property using SCSS variables
4+ like this:
5+
6+ ``` css
7+ $primary-action : #057A5B ;
8+
9+ .btn-primary {
10+ --button-color : $primary-action;
11+ }
12+ ```
13+
14+ After SCSS pre-processing, the resulting CSS will look like this:
15+
16+ ``` css
17+ .btn-primary {
18+ --button-color : $primary-action;
19+ }
20+ ```
21+
22+ Instead of the variable being translated into its declared value (` #057A5B ` in
23+ this case), it is left as is.
24+
25+ This is because CSS custom property syntax is unusual enough that it gets
26+ processed literally. The only way to incorporate a variable is with
27+ _ interpolation_ .
28+
29+ ``` css
30+ $primary-action : #057A5B ;
31+
32+ .btn-primary {
33+ --button-color : #{$primary-action};
34+ }
35+ ```
36+
37+ Wrapping the SCSS variable in interpolation syntax (` #{ ... } ` ) will do the
38+ job.
39+
40+ [ source] ( https://sass-lang.com/documentation/style-rules/declarations#custom-properties )
You can’t perform that action at this time.
0 commit comments