Re: [csswg-drafts] [css-values] Re-adding min() and max()?

One could also add `clamp()` which would take three parameters `value`, `startofrange` and `endofrange`.

What this function does is return `value` if value is inside the range, and if not, then returns either `startofrange` or `endofrange`, whichever is closest to `value`.

examples:
```css
width: clamp(500px, 10px, 999px); //returns 500px
width: clamp(1px, 100px, 9999px); //returns 100px
width: clamp(999999999px, 10px, 1000px); //returns 1000px
width: clamp(1px, 99999px, 10px); //returns 10px
width: clamp(1px, 99px, 99px); //returns 99px
```

It doesn't matter whether `startofrange` > `endofrange` or `startofrange` < `endofrange` or the trivial case of `startofrange` = `endofrange` (in which case it just returns `startofrange` and doesn't even check the value).

The behavior works slightly different when clamping angles, though, so beware that.

-- 
GitHub Notification of comment by gabriel-peracio
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/544#issuecomment-321498156 using your GitHub account

Received on Thursday, 10 August 2017 09:18:28 UTC