Skip to content

Instantly share code, notes, and snippets.

@awestmoreland
Last active July 19, 2021 19:47
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • 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%;
@kwn
Copy link

kwn commented Oct 9, 2014

Thx, you saved my day ;]

@grimzy
Copy link

grimzy commented Oct 15, 2014

Great, thanks 👍

@jdlich
Copy link

jdlich commented Feb 7, 2015

There's also the unquote function:

$value + unqoute("%")

@xino1010
Copy link

thanks

@arctic-pie
Copy link

Thanks

@abdeljail
Copy link

Thanks 😎😎😎

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