HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
The CSS math functions allow mathematical expressions to be used as property values. Here, we will explain the calc(), max() and min() functions
The calc()
function performs a calculation to be used as the property value.
CSS Syntax
Value | Description |
---|---|
expression | Required. A mathematical expression. The result will be used as the value. The following operators can be used: + - * / |
Let us look at an example:
Use calc() to calculate the width of a <div> element:
#div1 {
position: absolute;
left: 50px;
width: calc(100% - 100px);
border: 1px solid black;
background-color: yellow;
padding: 5px;
}
The max()
function uses the largest value,
from a comma-separated list of values, as the property value.
CSS Syntax
Value | Description |
---|---|
value1, value2, ... | Required. A list of comma-separated values - where the largest value is chosen |
Let us look at an example:
Use max() to set the width of #div1 to whichever value is largest, 50% or 300px:
#div1 {
background-color: yellow;
height: 100px;
width: max(50%, 300px);
}
The min()
function uses the smallest value,
from a comma-separated list of values, as the property value.
CSS Syntax
Value | Description |
---|---|
value1, value2, ... | Required. A list of comma-separated values - where the smallest value is chosen |
Let us look at an example:
Use min() to set the width of #div1 to whichever value is smallest, 50% or 300px:
#div1 {
background-color: yellow;
height: 100px;
width: min(50%, 300px);
}