Skip to content

Instantly share code, notes, and snippets.

@SvenJuergens
Last active June 27, 2024 07:55
Show Gist options
  • Save SvenJuergens/1a3cf4fc38f796180d04f006986f97b7 to your computer and use it in GitHub Desktop.
Save SvenJuergens/1a3cf4fc38f796180d04f006986f97b7 to your computer and use it in GitHub Desktop.
Responsive font calculator as scss mixin (based on https://websemantics.uk/tools/fluid-responsive-property-calculator/)
/* based on https://websemantics.uk/tools/fluid-responsive-property-calculator/ */
// Base for responsive calculation: Specifies the minimum and maximum size
// for which the size should be dynamically created
$min-vw: 375;
$max-vw: 1250;
@mixin responsive-property($min-value, $max-value,$property: font-size) {
$slope: math.div(($max-value - $min-value), ($max-vw - $min-vw));
$base: $min-value - ($slope * $min-vw);
#{$property}: clamp(#{$min-value}px, calc(#{$base}px + #{$slope * 100}vw), #{$max-value}px);
}
// Example usage
//.responsive-element {
// @include responsive-property(100, 200); // default property is font-size
// @include responsive-property(10, 50, padding);
// @include responsive-property(5, 25, margin);
// ...
//}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment