Add a <style> element to the document <head>.
<style>
<head>
Usage:
Example 1: Add the <style> with id, and repeated invoking will update the content instead of adding a new one.
id
import { addStyle } from "mazey";addStyle( "body { background-color: #333; }", { id: "test" }); Copy
import { addStyle } from "mazey";addStyle( "body { background-color: #333; }", { id: "test" });
Output:
<style id="test">body { background-color: #333; }</style> Copy
<style id="test">body { background-color: #333; }</style>
Example 2: Add the <style> without id, and repeated invoking will add a new one.
import { addStyle } from "mazey";addStyle("body { background-color: #444; }"); Copy
import { addStyle } from "mazey";addStyle("body { background-color: #444; }");
<style>body { background-color: #444; }</style> Copy
<style>body { background-color: #444; }</style>
Example 3: Combine genStyleString and addStyle to add multiple styles at once.
genStyleString
addStyle
import { genStyleString, addStyle } from "mazey";const xStyle = genStyleString( ".footer>.x-wish>a:first-child" + ",div.wish-flex>a[href^='https://github.com/chengchuu']" + ",.m-hide", [ "display: none" ]);const yStyle = genStyleString( ".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)", ]);addStyle(xStyle + yStyle, { id: "z-style" }); Copy
import { genStyleString, addStyle } from "mazey";const xStyle = genStyleString( ".footer>.x-wish>a:first-child" + ",div.wish-flex>a[href^='https://github.com/chengchuu']" + ",.m-hide", [ "display: none" ]);const yStyle = genStyleString( ".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)", ]);addStyle(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>
CSS text to add to the document.
Optional
Optional <style> element ID. An existing element with the same ID is updated instead of duplicated.
Whether non-empty CSS text was added or updated.
Add a
<style>element to the document<head>.Usage:
Example 1: Add the
<style>withid, and repeated invoking will update the content instead of adding a new one.Output:
Example 2: Add the
<style>withoutid, and repeated invoking will add a new one.Output:
Example 3: Combine
genStyleStringandaddStyleto add multiple styles at once.Output: