English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The calc() CSS function allows you to perform some calculations when declaring CSS property values. It can be used in the following situations: <length>, <frequency>, <angle>, <time>, <number>, or <integer>.
Use the calc() function to calculate the width of the <div> element:
!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Basic Tutorial(oldtoolbag.com)<//title> <style> #div1 { position: absolute; left: 50px; width: calc(100% - 100px); border: 1px solid black; background-color: yellow; padding: 5px; text-align: center; } </style> </head> <body> <p>Create a div spanning the screen, with 50px gap:<//p> <div id="div1">some text...</div> </body> </html>Test and See ‹/›
The calc() function is used for dynamic calculation of length values.
It should be noted that there must be a space before and after the operator, for example:width: calc(100% - 10px)
;
Any length value can be calculated using the calc() function;
The calc() function supports "+", "-", "*", "/Operation;
The calc() function uses standard mathematical operator precedence rules;
Supported Version: CSS3
The numbers in the table represent the first browser version number that supports the function.
"webkit" or "moz" or "o" prefixes the number to indicate the first version of the function supported.
Function | |||||
---|---|---|---|---|---|
calc() | 26.0 19.0 -webkit- | 9.0 | 16.0 4.0 -moz- | 7.0 6.0 -webkit- | 15.0 |
calc(expression)
Value | Description |
---|---|
expression | Required, a mathematical expression, the result of which will be used as the return value after the operation. |