Create CSS rule text from a selector and an array of declarations.
Declarations are joined with semicolons. The selector and declarations are used verbatim without validation or escaping; this function does not modify the DOM.
Usage:
const ret1 = createCSSRule(".a", [ "color:red" ]);const ret2 = createCSSRule("#b", [ "color:red", "font-size:12px" ]);console.log(ret1);console.log(ret2); Copy
const ret1 = createCSSRule(".a", [ "color:red" ]);const ret2 = createCSSRule("#b", [ "color:red", "font-size:12px" ]);console.log(ret1);console.log(ret2);
Output:
.a{color:red;} #b{color:red;font-size:12px;} Copy
.a{color:red;} #b{color:red;font-size:12px;}
Example: Combine createCSSRule and injectStyle to add multiple styles at once.
createCSSRule
injectStyle
import { createCSSRule, injectStyle } from "mazey";const xStyle = createCSSRule( ".footer>.x-wish>a:first-child" + ",div.wish-flex>a[href^='https://github.com/chengchuu']" + ",.m-hide", [ "display: none" ]);const yStyle = createCSSRule( ".footer>.y-wish:before", [ `content: 'Copyright (c) chengchuu'`, "color: inherit", "padding-inline-start: var(--y-wish-1_5)", "padding-inline-end: var(--y-wish-1_5)", "padding-top: var(--y-wish-1)", "padding-bottom: var(--y-wish-1)", ]);injectStyle(xStyle + yStyle, { id: "z-style" }); Copy
import { createCSSRule, injectStyle } from "mazey";const xStyle = createCSSRule( ".footer>.x-wish>a:first-child" + ",div.wish-flex>a[href^='https://github.com/chengchuu']" + ",.m-hide", [ "display: none" ]);const yStyle = createCSSRule( ".footer>.y-wish:before", [ `content: 'Copyright (c) chengchuu'`, "color: inherit", "padding-inline-start: var(--y-wish-1_5)", "padding-inline-end: var(--y-wish-1_5)", "padding-top: var(--y-wish-1)", "padding-bottom: var(--y-wish-1)", ]);injectStyle(xStyle + yStyle, { id: "z-style" });
<style id="z-style">.footer>.x-wish>a:first-child,div.wish-flex>a[href^='https://github.com/chengchuu'],.m-hide{display: none;}.footer>.y-wish:before{content: 'Copyright (c) chengchuu';color: inherit;padding-inline-start: var(--y-wish-1_5);padding-inline-end: var(--y-wish-1_5);padding-top: var(--y-wish-1);padding-bottom: var(--y-wish-1);}</style> Copy
<style id="z-style">.footer>.x-wish>a:first-child,div.wish-flex>a[href^='https://github.com/chengchuu'],.m-hide{display: none;}.footer>.y-wish:before{content: 'Copyright (c) chengchuu';color: inherit;padding-inline-start: var(--y-wish-1_5);padding-inline-end: var(--y-wish-1_5);padding-top: var(--y-wish-1);padding-bottom: var(--y-wish-1);}</style>
The CSS selector and declaration block.
Create CSS rule text from a selector and an array of declarations.
Declarations are joined with semicolons. The selector and declarations are used verbatim without validation or escaping; this function does not modify the DOM.
Usage:
Output:
Example: Combine
createCSSRuleandinjectStyleto add multiple styles at once.Output: