@creenv/inject-css

@creenv/inject-css JS library on GitHub @creenv/inject-css JS library on npm Download @creenv/inject-css JS library

Injects some css into the head, inline <style>

Version 0.0.1 License MIT
@creenv/inject-css has no homepage
@creenv/inject-css JS library on GitHub
@creenv/inject-css JS library on npm
Download @creenv/inject-css JS library
Keywords
creenvinjectcss

Css to head

Injects some text within <style> tags efef into the <head>

Usage

var injectCss = require('css-to-head');

var myCss = `
  .basic-css {
    width: 50%;
    height: 10px;
  }
  #other-css {
    color: red;
  }
`;

injectCss(myCss, "id-appended-to-style-tag");

// won't be injected cause "id-appended-to-style-tag" was already injected
injectCss(myCss, "id-appended-to-style-tag");

// will be injected cause param 3 is set to false
injectCss(myCss, "id-appended-to-style-tag", false);

// will be injected cause id-2 was not already injected
injectCss(myCss, "id-2");

result

<head>
  <style id="id-2">
    .basic-css {
      width: 50%;
      height: 10px;
    }
    #other-css {
      color: red;
    }
  </style>
  <style id="id-appended-to-style-tag">
    .basic-css {
      width: 50%;
      height: 10px;
    }
    #other-css {
      color: red;
    }
  </style>
  <style id="id-appended-to-style-tag">
    .basic-css {
      width: 50%;
      height: 10px;
    }
    #other-css {
      color: red;
    }
  </style>
</head>