Skip to content

Commit 9d05e0b

Browse files
authored
Merge pull request #191 from BeAPI/fix/fluid-size
Évolution de la fonction `fluid-size`
2 parents ce60c30 + 1f01d89 commit 9d05e0b

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

‎src/scss/common/02-functions/_fluid-size.scss‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
*
44
* Converted from source: : https://www.aleksandrhovhannisyan.com/blog/fluid-type-scale-with-css-clamp/
55
*
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.
78
*
89
* @author Cédric Andrietti
910
*
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)
1213
* @param $start -> Start breakpoint
1314
* @param $end -> End breakpoint
1415
*
@@ -19,16 +20,23 @@
1920
* line-height: #{fluid-size(1.05, 1.2)};
2021
* }
2122
*
23+
* // Larger on mobile, smaller on desktop
24+
* .hero {
25+
* padding-top: #{fluid-size(40px, 3px)};
26+
* }
27+
*
2228
*/
2329

2430
@use "sass:map";
2531
@use "sass:math";
2632
@use "../00-variables/config" as *;
2733
@use "../02-functions/strip-units" as *;
2834

29-
@function fluid-size($min, $max, $start: 7xs, $end: md) {
35+
@function fluid-size($from, $to, $start: 7xs, $end: l) {
3036
$start: math.div(map.get($breakpoints, $start), 100);
3137
$end: math.div(map.get($breakpoints, $end), 100);
38+
$lower: math.min($from, $to);
39+
$upper: math.max($from, $to);
3240

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});
3442
}

0 commit comments

Comments
 (0)