Skip to content

Instantly share code, notes, and snippets.

@Daniel-Walsh
Last active November 17, 2021 22:40
Show Gist options
  • Save Daniel-Walsh/8e563e9c9cf56bf1d8a634e0a29e34b2 to your computer and use it in GitHub Desktop.
Save Daniel-Walsh/8e563e9c9cf56bf1d8a634e0a29e34b2 to your computer and use it in GitHub Desktop.
Add em spacing to TailwindCSS #tailwindcss
// 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