Skip to content

Instantly share code, notes, and snippets.

@awestmoreland
Last active July 19, 2021 19:47
Show Gist options
  • Save awestmoreland/5554996 to your computer and use it in GitHub Desktop.
Save awestmoreland/5554996 to your computer and use it in GitHub Desktop.
Concatenation of sass value+units. See also: http://stackoverflow.com/a/9862328
// Set sizes without units
$basefont: 20;
$total-width-px: 1169;
$column-width-px: 72;
// Concatenation of units by addition results in conversion to string. This is bad
$basefont-px: $basefont+'px'; // = "20px"
// Conversion to pixels using multiplication
$basefont-px: $basefont*1px; // = 20px;
// Conversion to percentages using multiplication
$column-width: ($column-width-px/($total-width-px/100))*1%; // = 6.159110351%;
@abdeljail
Copy link

Thanks 😎😎😎

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