Skip to content

Instantly share code, notes, and snippets.

@siwalikm
Created February 27, 2018 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save siwalikm/573a039d990c470295e29d608f873ce6 to your computer and use it in GitHub Desktop.
Save siwalikm/573a039d990c470295e29d608f873ce6 to your computer and use it in GitHub Desktop.
function to convert your css string to downloadable file
cssStringToFileDownloader = function (cssString) {
var blob = new Blob([cssString], { type: 'text/css' });
var el = document.createElement('a');
el.download = 'cssPaletteBundle.css';
el.href = URL.createObjectURL(blob);
el.dataset.downloadurl = ['text/css', el.download, el.href].join(':');
el.style.display = 'none';
document.body.appendChild(el);
el.click();
document.body.removeChild(el);
setTimeout(function () { URL.revokeObjectURL(el.href); }, 1500);
};
/* cssStringToFileDownloader('body{padding:12px;}') */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment