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