Is it possible to do something like this
max-width: calc(max(500px, 100% - 80px))
or
max-width: max(500px, calc(100% - 80px)))
in CSS?
The + and - operators must be surrounded by whitespace. For instance, calc(50% -8px) will be parsed as a percentage followed by a negative length — an invalid expression — while calc(50% - 8px) is a percentage followed by a subtraction operator and a length.
CSS calc() is a function used for simple calculations to determine CSS property values right in CSS. The calc() function allows mathematical expressions with addition (+), subtraction (-), multiplication (*), and division (/) to be used as component values.
max() The max() CSS function lets you set the largest (most positive) value from a list of comma-separated expressions as the value of a CSS property value. The max() function can be used anywhere a <length> , <frequency> , <angle> , <time> , <percentage> , <number> , or <integer> is allowed.
A 'pure' css solution actually is possible now using media queries:
.yourselector {
max-width: calc(100% - 80px);
}
@media screen and (max-width: 500px) {
.yourselector {
max-width: 500px;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With