Skip to content

Instantly share code, notes, and snippets.

@daltonmenezes
Created February 16, 2022 02:38
Show Gist options
  • Save daltonmenezes/9cac0767af3d248eddc61e8a57b2b44d to your computer and use it in GitHub Desktop.
Save daltonmenezes/9cac0767af3d248eddc61e8a57b2b44d to your computer and use it in GitHub Desktop.
A pixel to rem utility function
function pixelToRem(...values: number[]) {
return values
.reduce((acc, current) => (acc += current / 16 + `rem `), "")
.trim();
}
pixelToRem(13, 20) // 0.8125rem 1.25rem
@daltonmenezes
Copy link
Author

Another solution:

const pixelToRem = (...values: number[]) =>
  values.map((number) => number / 16 + "rem").join(" ");

@felipecastrosales
Copy link

you are a best, champ! 🏆

@nicolasteofilo
Copy link

very nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment