Guest User

Untitled

a guest
Nov 19th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. /* 'rem' is a Sass mixin that converts pixel values to rem values
  2. * Returns 2 lines of code — regular pixel values and converted rem values
  3. *
  4. * Sample input:
  5. * .element {
  6. * @include rem('padding',10px 0 2px 5px); }
  7. *
  8. * Sample output:
  9. * .element {
  10. * padding: 10px 0 2px 5px;
  11. * padding: 1rem 0 0.2rem 0.5rem; }
  12. */
  13.  
  14. // Baseline, measured in pixels
  15. // Value should be same as font-size value for the html element
  16. // If html element's font-size set to 62.5% (of the browser's default 16px),
  17. // then variable below would be 10px.
  18. $baseline_px: 16px;
  19.  
  20. @mixin rem($property, $px_values) {
  21. // Convert the baseline into rems
  22. $baseline_rem: ($baseline_px / 1rem);
  23. // Print the first line in pixel values
  24. #{$property}: $px_values;
  25. // If only one (numeric) value, return the property/value line for it.
  26. @if type-of($px_values) == 'number' {
  27. #{$property}: $px_values / $baseline_rem;
  28. }
  29. // If more than one value, create list & perform equations on each value
  30. @else {
  31. // Create an empty list that we can dump values into
  32. $rem_values: ();
  33. @each $value in $px_values {
  34. // If the value is zero, return 0
  35. @if $value == 0 {
  36. $rem_values: append($rem_values, $value);
  37. }
  38. // If the value is not zero, convert it from px to rem
  39. @else {
  40. $rem_values: append($rem_values, ($value / $baseline_rem) );
  41. }
  42. }
  43. // Return the property and its list of converted values
  44. #{$property}: $rem_values;
  45. }
  46. }
Add Comment
Please, Sign In to add comment