Last active
November 17, 2021 22:40
-
-
Save Daniel-Walsh/8e563e9c9cf56bf1d8a634e0a29e34b2 to your computer and use it in GitHub Desktop.
Add em spacing to TailwindCSS #tailwindcss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Adds new spacing classes using `em` instead of `rem`. For example: | |
// .w-4~ | |
// .h-8~ | |
// .mx-12~ | |
// .pl-6~ | |
const defaultTheme = require("tailwindcss/defaultTheme"); | |
module.exports = { | |
//... general configuration | |
theme: { | |
//... theme configuration | |
extend: { | |
//... theme extend configuration | |
spacing: { | |
...(function () { | |
const emSpacing = {}; | |
Object.keys(defaultTheme.spacing).forEach((key) => { | |
const size = defaultTheme.spacing[key]; | |
if (size.indexOf("rem") > -1) { | |
emSpacing[`${key}\~`] = size.replace("rem", "em"); | |
} | |
}); | |
return emSpacing; | |
})(), | |
}, | |
}, | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment