An object where keys are CSS selectors (or camelCased properties) and values are CSS properties or nested rule objects.
&, that character will be replaced by the parent selector., characters, each combining with the parent selector with or semantics.'@' define at-rules like media queries. They may be nested within regular selectors.If true, styles are inserted globally without prefixing.
If false (default), all selectors are prefixed with a unique generated
class name (e.g., .AbdStl1) to scope the styles.
The unique class name prefix used for scoping (e.g., .AbdStl1), or an empty string
if global was true. Use this prefix with $ to apply the styles.
const scopeClass = insertCss({
color: 'red',
padding: '10px',
'&:hover': { // Use '&' for the root scoped selector
backgroundColor: '#535'
},
'.child-element': { // Nested selector
fontWeight: 'bold'
},
'@media (max-width: 600px)': {
padding: '5px'
}
});
// scopeClass might be ".AbdStl1"
// Apply the styles
$(scopeClass, () => { // Add class to the div
$(`:Scoped content`);
$('div.child-element:Child'); // .AbdStl1 .child-element rule applies
});
Inserts CSS rules into the document, optionally scoping them with a unique class name.
Takes a JavaScript object representation of CSS rules. camelCased property keys are converted to kebab-case (e.g.,
fontSizebecomesfont-size).