In some SCSS files, I see the following:
:global { /* ... */ }
I don't know if it is an SCSS feature or a CSS feature. I tried searching about it but couldn't find any good results at first sight.
Traditionally, websites are styled using global CSS files. Globally-scoped CSS rules are declared in external . css stylesheets, and CSS specificity and the Cascade determine how styles are applied.
In Stylable, selectors are namespaced to the stylesheet. However there might be cases where you want to target global selectors without Stylable namespacing them, For that you can use the :global() selector.
module. scss is SCSS file with CSS modules. According to the repo, CSS modules are: CSS files in which all class names and animation names are scoped locally by default.
To import a CSS Module into the corresponding component, import the css modules stylesheet as styles or [name]Styles : In JSX, use the defined CSS class as a className prop like so: From here, you can add as many other CSS modules you'd like, just remember to import each as a different name.
This operator is used in CSS Modules. Modular CSS uses a CSS Modules compiler to scope CSS styles within their respective modules (e.g., React component).
Here's an example from a React module (in the file ErrorMessaging.less
for the ErrorMessaging.jsx
React component):
:global(.ocssContainer) { .ui_column { padding-left: 0; } }
This gets compiled into:
.ErrorMessaging__alertContainer--1I-Cz .ocssContainer .ErrorMessaging__ui_column--3uMUS { padding-left: 0; }
But now I add a :global
modifier onto .ui_column
:
:global(.ocssContainer) { :global(.ui_column) { padding-left: 0; } }
And this is what it compiles to:
.ErrorMessaging__alertContainer--1I-Cz .ocssContainer .ui_column { padding-left: 0; }
Now .ui_column
can apply to any child element with that style, including in a child React component, and not just .ui_column
elements that are part of the ErrorMessaging
React component.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With