The calc() function can be used anywhere in a length is required by a CSS properties. calc() allows mathematical expressions with addition (‘+’), subtraction (‘-’), multiplication (‘*’), and division (‘/’) to be used as component values. The values themselves can be a mixture of percentages, integers, numbers, lengths such as em or cm, angles or even time values ( seconds, milliseconds). Calc is useful for computing certain values that are not known at the development time or to set formulated values rather that arbitrary ones.
ExamplesThis is an example of how can you use calc in CSS
.header {
position:relative;
margin: 0px auto;
width: 80%;
width: calc(100% - 100px);
border: solid black 1px;
box-shadow: 5px 5px #999;
margin-top: 40px;
padding: 10px;
text-align: center;
}
.header:hover {
width: calc(100% / 3 - 2 * 1em);
width: 25%;
}
Notes
If you divide by zero it will cause an error in the HTML parser. Also the return value that will be computed must comply within the range of the relevant CSS target. For example width or height cannot be negative so it will be reverted to 0;
Related specificationsRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4