Skip to content
This repository has been archived by the owner on Nov 20, 2022. It is now read-only.
/ inject-css-string Public archive

Inject an unique CSS string via a `<style>` tag into the `<head>`.

License

Notifications You must be signed in to change notification settings

LSVH/inject-css-string

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

inject-css-string

Inject an unique CSS string via a <style> tag into the <head>.

NPM

Usage

const injectCssString = require('inject-css-string');
const createCssRule = require('convert-to-css').createCssRule; // npm i -S 'convert-to-css'

const css = createCssRule({
	'.foo': {
		padding: 10,
	},
}); // results in: '.foo{padding:10px}'

injectCssString(css);
injectCssString(css);
console.log(document.head.innerHTML); // logs: '<style>.foo{padding:10px}</style>'

document.head.innerHTML = ''; // empty head, removes previously added style tags

injectCssString(css, 'bar');
injectCssString(css, 'bar');
console.log(document.head.innerHTML); // logs: '<style id="ics-bar">.foo{padding:10px}</style>'

License

MIT © LSVH

About

Inject an unique CSS string via a `<style>` tag into the `<head>`.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •