Here you go getting the computed style for a given element and giving the user the option to save this in a css file. There can be made tweaks to it of course, but basically this is it:
HTML:
<button id="b" href="#">export to CSV</button>
CSS:
#b {
background: linear-gradient(to bottom right, #fff, #0af);
border: solid 1px #0af;
border-radius: 10px;
color: #333;
cursor: pointer;
margin: 10px;
outline: none;
}
#b:hover {
background: linear-gradient(to bottom right, #fff, #0af, #07c);
}
and Javascript (JQuery):
b = $('#b');
function css(a) {
var sheets = document.styleSheets,
o = {};
for (var i in sheets) {
var rules = sheets[i].rules || sheets[i].cssRules;
for (var r in rules) {
if (a.is(rules[r].selectorText)) {
o = $.extend(o, css2json(rules[r].style), css2json(a.attr('style')));
}
}
}
return o;
}
function css2json(css) {
var s = {};
if (!css) return s;
if (css instanceof CSSStyleDeclaration) {
for (var i in css) {
if ((css[i]).toLowerCase) {
s[(css[i]).toLowerCase()] = (css[css[i]]);
}
}
} else if (typeof css == "string") {
css = css.split("; ");
for (var i in css) {
var l = css[i].split(": ");
s[l[0].toLowerCase()] = (l[1]);
}
}
return s;
}
myCSS = objToString(css(b));
function objToString(obj) {
var str = '{\n';
for (var p in obj) {
if (obj.hasOwnProperty(p)) {
str += ' ' + p + ': ' + obj[p] + ';\n';
}
}
str += '}';
return str;
}
function download(text, name, type) {
var a = document.createElement("a");
var file = new Blob([text], {
type: type
});
a.href = URL.createObjectURL(file);
a.download = name;
a.click();
}
b.on('click', function() {
download(myCSS, 'test.css', 'text')
});
oh and of course the jsFiddle to test it...
Credits going for Awesomeness01, Brett Zamir and marknadal