@creenv/inject-css

0.0.1 • Public • Published

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>

Readme

Keywords

Package Sidebar

Install

npm i @creenv/inject-css

Weekly Downloads

0

Version

0.0.1

License

MIT

Unpacked Size

4.15 kB

Total Files

4

Last publish

Collaborators

  • bcrespy