Skip to content

Instantly share code, notes, and snippets.

@wingedpig
wingedpig / inlinestyles.js
Created August 31, 2023 04:52
A function to calculate the computed styles of elements and write them as inline styles
const attributesToInline = ['flex', 'flex-basis', 'flex-direction', 'flex-grow', 'display', 'max-width', 'max-height', 'overflow-y', 'overflow-x'];
function inlineStyles(element) {
// Get computed styles of the element
const computedStyle = window.getComputedStyle(element);
let styleString = '';
for (const attr of attributesToInline) {
const value = computedStyle.getPropertyValue(attr);
if (value) {
if ((attr == "overflow-x" || attr == "overflow-y") && value == "visible") {