Skip to content

Instantly share code, notes, and snippets.

@panayotoff
Last active November 9, 2015 11:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save panayotoff/86647b9c150dcef019e6 to your computer and use it in GitHub Desktop.
Save panayotoff/86647b9c150dcef019e6 to your computer and use it in GitHub Desktop.
Sometimes the designer gives you static design with column widths, that doesn't fit exactly in the grid system. For example the container is 200px, and there are two columns - 110px and 90 px. To make a fluid design, you have to represent them as percentages - so just use this little scss function that will return the appropriate width, represen…
//--------------------------------------------------------------
// Width to ratio
// You can pass to the mixin the target and the context in units:
// fixed-to-fluid(35px, 100px);
// Or you can pass just ratio from the pixels
// fixed-to-fluid(35/100);
//--------------------------------------------------------------
@function fixed-to-fluid($target-width, $context-width:false) {
//Process ratio
@if (type-of($target-width) == "number" and unitless($target-width) and $context-width == false) {
@return percentage($target-width);
}
//Process target and context
@if (comparable($target-width, $context-width)) {
@return percentage($target-width / $context-width);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment