question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CSS min() and max() re-introduced

See original GitHub issue

(edited by @nex3)


https://drafts.csswg.org/css-values/#calc-notation A (maybe) quick solution could be to add a @ prefix – and while at it extend the math methods to cover pow, sqrt, cos, etc…

 @min($numbers...)
 @max($numbers...)
 @abs($number)
 @percentage($number)
 @round($number)
 @ceil($number)
 @floor($number)
 @random($limit)
 //  Sadly missing from Sass at this point 
 @pow($base, $exponent)
 @sqrt($number)
 @cos($number)
 ... 
  

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:26 (11 by maintainers)

github_iconTop GitHub Comments

59reactions
jrjacobs24commented, Feb 21, 2018

I ran into this issue today as well when converting my src from Less to Scss. I found that using Sass Function unquote rendered the correct output I was looking for.

In my Scss:

.example {
  right: unquote('max(#{$global-margin}, env(safe-area-inset-right))');
}

In my CSS:

.example {
  right: max(15px, env(safe-area-inset-right));
}

I went this method instead of using calc(max(...)) or m#{a}x(...) routes because the first one made the resulting code look messy, and the second one just felt too hacky. Anyways, hope this helps someone.

43reactions
swordraycommented, Oct 30, 2018

Define CSS max() and min() functions.

@function max($numbers...)
  @return m#{a}x(#{$numbers})

@function min($numbers...)
  @return m#{i}n(#{$numbers})

These will keep your own code clean.

.example
  right: max(15px, env(safe-area-inset-right))
Read more comments on GitHub >

github_iconTop Results From Across the Web

ISSUE-203: Reintroduce min() and max() - W3C
Product: CSS4 Values and Units ; Raised by: Elika Etemad ; Opened on: 2011-12-12 ; Description: min() and max() were deferred due to...
Read more >
min(), max(), and clamp(): three logical CSS functions to use ...
Showing how the max() function selects a value based on a list of options and its parent. See Demo on Codepen.
Read more >
A guide to the min(), max(), and clamp() CSS functions
min() : Lets you set the smallest (most negative) value from a list of comma-separated expressions as the value of a CSS property...
Read more >
Calc of max, or max of calc in CSS - Stack Overflow
No you cannot. max() and min() have been dropped from CSS3 Values and Units. They may be re-introduced in CSS4 Values and Units...
Read more >
min() - CSS: Cascading Style Sheets - MDN Web Docs
When using min() to set a maximum font size, ensure that the font can still be scaled at least 200% for readability (without...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found