Skip to content

Instantly share code, notes, and snippets.

@yuheiy
Created November 29, 2016 10:54
Show Gist options
  • Save yuheiy/a50c5072866e6223a6a72d5082f00911 to your computer and use it in GitHub Desktop.
Save yuheiy/a50c5072866e6223a6a72d5082f00911 to your computer and use it in GitHub Desktop.
$width-comp-size: 640px;
@function strip-unit($n) {
@return $n / ($n * 0 + 1);
}
@function w($size) {
$width: $size / $width-comp-size * 100%;
@return $width;
}
@function m($size) {
$margin: calc(100vw * #{strip-unit($size)} / #{strip-unit($width-comp-size)});
@return $margin;
}
.foo {
width: w(125px);
}
.bar {
margin-bottom: m(20px);
}
.baz {
width: w(40px);
margin-bottom: m(270px);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment