Skip to content

Instantly share code, notes, and snippets.

@aebsr
Last active December 16, 2015 00:19
Show Gist options
  • Save aebsr/5346339 to your computer and use it in GitHub Desktop.
Save aebsr/5346339 to your computer and use it in GitHub Desktop.
Adaptive font size Less mixin & px fallback
.font-size(@font-size: 16, @mobile-ratio: 66) {
@rem: (@font-size / 10);
@percent: (@mobile-ratio / 100);
font-size: (@font-size * 1px);
font-size: ~"@{rem}rem";
@media @mobile {
@rem: ((@font-size / 10) * @percent);
font-size: (@font-size * 1px);
font-size: ~"@{rem}rem";
}
}
// Generated CSS
html {
font-size: .625em;
}
body {
font-size: 18px;
font-size: 1.8rem;
}
@media screen only (max-width: 600px) {
body {
font-size: 18px;
font-size: 1.1880000000000002rem;
}
}
@import 'font-size';
@mobile: ~"screen only (max-width: 600px)";
html {
font-size: .625em;
}
body {
.font-size(18);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment