If the user wants to perform mathematical operations in CSS such as multiplication, addition, subtraction or division, they can use calc()
function in CSS.
calc()
is a function that performs calculation to be used as the value of property.
Syntax
.class-name{
property: calc(expression)
}
where expression is mathematical expression with + - * / operators. It can be used anywhere angle, length, frequency, number, integer, time or percentage is required.
calc() can be used as an alternative to grid but it's not recommended to do the same.
Points to remember before you use calc()
β’ Only + and - operators should be surrounded by whitespaces.
calc(50% - 80px)
β’ You can now use calc()
with media query.
β’ calc()
is mainly used when working with mixed units.
width: calc(50rem - 3px);
β’ You can nest calc(calc())
.class-name {
width: calc(
calc(20% / 5)
+
calc(4rem * 2)
);
}
Follow us on Instagram
Top comments (0)