JSFiddle - React, Tailwind, and code Playground
HTML
<div class="hello-world"></div>
<pre></pre>
CSS
.hello-world {
display: inline-block;
border-radius: 50%;
background: blue;
}
.hello-world {}
.hello-world {
width: 50px;
height: 50px;
}
.hello-world {
border: 3px solid red;
}
JavaScript
const getClassStyles = className =>
[...document.styleSheets].reduce((styles, { cssRules }) => {
return [...cssRules]
.filter(n => n.selectorText === `.${className}`)
.reduce((styles, { cssText }) => {
return (cssText
.match(/[\w\-]+: [^;]+/g) || [])
.map(n => n.split(': '))
.reduce((styles, [ k, v ]) => (styles[k] = v, styles), styles);
}, styles);
}, {});
const styles = getClassStyles('hello-world');
document.querySelector('pre').textContent = JSON.stringify(styles, null, 2);