This article describes the CSS3 calc() value. This feature hasn’t landed yet in any Firefox tree but work to implement it is underway.
Firefox will support the CSS calc() value, which lets you compute a length value using an arithmetic expression. This means you can use it to define the sizes of divs, the values of margins, the widths of borders, and so forth.
Here is an example of a layout which would be tricky to setup without the calc() function:
/* * Two divs aligned, split up by a 1em margin */ #a { width:75%; margin-right: 1em; } #b { width: -moz-calc(25% - 1em); } |
This example makes sure an input text field won’t overlap its parent:
input { padding:2px; border:1px solid black; display:block; width: -moz-calc(100% - 2 * 3px); } |
One particularly powerful feature of the calc() function that you can combine different units in the same computation:
width: -moz-calc(3px + 50%/3 - 3em + 1rem); |
The current implementation supports the +, -, *, /, mod, min, and max operators.
We’ll also support the min() and max() functions, which could be used like this:
div { height: -moz-min(36pt, 2em); width: -moz-max(50%, 18px); } |
For more details, see:
Pingback from Firefox 4: CSS3 cals() ✩ Mozilla 웹 기술 블로그 on June 14th, 2010 at 8:47 pm:
Pingback from Prøv Firefox 4 Beta! « MozillaDanmarks blog on August 12th, 2010 at 6:22 am:
Pingback from Web Designer Notebook » The Wonderful calc() Function on June 13th, 2011 at 3:36 pm:
Pingback from 55 Best CSS3 Tutorials 2011 | Web Development | iDesignow on July 12th, 2011 at 10:16 am:
Pingback from 85 The Most Useful CSS3 Tutorials | Bashooka on April 14th, 2012 at 4:02 am: