The max function

The max function allows you to select the maximum of passed values. The function takes two or more values ​​as parameters, separated by commas, and returns the maximum of them.

Syntax

cssselector {
  property: max(value1, value2);
}

Example

Now the block width will be either 300px or 50% of the parent, whichever is greater:

html<div id="parent">
  <div id="child"></div>
</div>
css#child {
  width: max(300px, 50%);
  height: 100px;
  margin: 0 auto;
  border: 1px solid red;
}
#parent {
  border: 1px solid green;
}

Результат:

See also

  • the min function
    that returns a minimum value
  • the calc function
    that calculates property values