css calc函数用法
The calc()
function lets you perform basic math operations on values, and it’s especially useful when you need to add or subtract a length value from a percentage.
calc()
函数可让您对值执行基本的数学运算,当您需要从百分比中添加或减去长度值时,该功能特别有用。
This is how it works:
它是这样工作的:
div {
max-width: calc(80% - 100px)
}
It returns a length value, so it can be used anywhere you expect a pixel value.
它返回一个长度值,因此可以在期望像素值的任何地方使用。
You can perform
你可以表演
additions using
+
使用
+
加法subtractions using
-
使用
-
减去multiplication using
*
*
相乘division using
/
除法使用
/
One caveat: with addition and subtraction, the space around the operator is mandatory, otherwise it does not work as expected.
一个警告:加减法运算符周围的空间是强制性的,否则将无法正常工作。
Examples:
例子:
div {
max-width: calc(50% / 3)
}
div {
max-width: calc(50% + 3px)
}
css calc函数用法