Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@paales
Created July 5, 2016 09:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paales/764f88527926d6dd04286705ef91a271 to your computer and use it in GitHub Desktop.
Save paales/764f88527926d6dd04286705ef91a271 to your computer and use it in GitHub Desktop.
Responsive sizing
//
// Responsive Size
// ---------------------------------------------
// Responsive size mixin, dynamic sizes based on viewport size, implemented with calc()
// Optional fallback implemented for some unsupported browsers, average of small/large
// http://caniuse.com/#search=viewport
// Usage:
//
// h1 {
// .responsive-size(25px, 40px);
// font-size: @size-fallback;
// font-size: @size;
// }
// The result is that the font-size is 25px on 320vmin, and 40px on 1440vmin
// Everything in between in dynamically calculated: ex. 768vmin = ~31x, 1024vmin = ~34px
.responsive-size(@small, @large, @unit: vmin, @small-vmin: 320, @large-vmin: 1440, @fallback-vmin: 768) {
@growth: unit((@large - @small) / (@large-vmin - @small-vmin));
@base: round(@small - (@growth * @small-vmin), 1);
@vsize: round((@growth * 100), 2);
@size-fallback: round((@small + @large) / 2);
@size: calc(~"@{base} + @{vsize}@{unit}");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment