Skip to content

Instantly share code, notes, and snippets.

@EvanLovely
Last active August 29, 2015 14:06
Show Gist options
  • Save EvanLovely/1fc0362f69daed135614 to your computer and use it in GitHub Desktop.
Save EvanLovely/1fc0362f69daed135614 to your computer and use it in GitHub Desktop.
Turn pixels into percentages easily. #sass__calculators

Useage

.block {
  padding: 0 res-width(10px);
}

The above code, assuming $site-width is set to 1280px, would return "0.78125%".

Overriding Container Width

.block {
  padding: 0 res-width(10px, 500px);
}

This would return "2%".

// calculate percentage widths from pixels based on site width (or other widths)
// Useage: `padding-left: res-width(10px);`
@function res-width($pixels, $container: $site-width) {
@return percentage($pixels / $container);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment