|
3 | 3 | * |
4 | 4 | * Converted from source: : https://www.aleksandrhovhannisyan.com/blog/fluid-type-scale-with-css-clamp/ |
5 | 5 | * |
6 | | - * Convert value px to fluid typography and spacing using clamp |
| 6 | + * Convert value px to fluid typography and spacing using clamp. |
| 7 | + * Supports both growing and shrinking scales between breakpoints. |
7 | 8 | * |
8 | 9 | * @author Cédric Andrietti |
9 | 10 | * |
10 | | - * @param $min -> Minimal display size (mobile) |
11 | | - * @param $max -> Maximal display size (Desktop) |
| 11 | + * @param $from -> Size at the start breakpoint (mobile) |
| 12 | + * @param $to -> Size at the end breakpoint (desktop) |
12 | 13 | * @param $start -> Start breakpoint |
13 | 14 | * @param $end -> End breakpoint |
14 | 15 | * |
|
19 | 20 | * line-height: #{fluid-size(1.05, 1.2)}; |
20 | 21 | * } |
21 | 22 | * |
| 23 | + * // Larger on mobile, smaller on desktop |
| 24 | + * .hero { |
| 25 | + * padding-top: #{fluid-size(40px, 3px)}; |
| 26 | + * } |
| 27 | + * |
22 | 28 | */ |
23 | 29 |
|
24 | 30 | @use "sass:map"; |
25 | 31 | @use "sass:math"; |
26 | 32 | @use "../00-variables/config" as *; |
27 | 33 | @use "../02-functions/strip-units" as *; |
28 | 34 |
|
29 | | -@function fluid-size($min, $max, $start: 7xs, $end: md) { |
| 35 | +@function fluid-size($from, $to, $start: 7xs, $end: l) { |
30 | 36 | $start: math.div(map.get($breakpoints, $start), 100); |
31 | 37 | $end: math.div(map.get($breakpoints, $end), 100); |
| 38 | + $lower: math.min($from, $to); |
| 39 | + $upper: math.max($from, $to); |
32 | 40 |
|
33 | | - @return clamp(#{$min}, #{$min} + (1vw - #{$start}px) / #{$end - $start} * #{strip-units($max - $min)}, #{$max}); |
| 41 | + @return clamp(#{$lower}, #{$from} + (1vw - #{$start}px) / #{$end - $start} * #{strip-units($to - $from)}, #{$upper}); |
34 | 42 | } |
0 commit comments