When the specification says ...
Each property that allows percentages also defines a value that the percentage points to.
... this definition is given by the specification, and then the corresponding user agent implements the calculation in accordance with the specification. The specification makes no reference to user percentage calculations. If I am at risk of guesswork, probably because it has changed how the CSS inline works, it could potentially open developers to many complications.
The calc() function, introduced here in the same spec you refer to, by itself does not allow you to specify a CSS property of either one element or another element, which means, for example, that you cannot do something like this :
.text { height: 100px; line-height: calc(100% * height); }
However, there is a recently published project called CSS Custom Properties for cascading variables that allows authors to specify their own property values and use them in arbitrary rule sets in the stylesheet. Although the module itself does not discuss how users can determine the percentage, it discusses the use of cascading variables using calc() .
This is very promising: since you can already do the multiplication and division with calc() , you can fully emulate the percentage calculations by multiplying by a decimal number instead of a percentage (or just use a cascading value, as for 100%). You can even force properties that usually do not accept percentages, such as border-width , so that their values are calculated based on some other property using this method.
Here is an example with an interactive proof of concept that works in Firefox 31 and later, where the current project is being implemented with this email:
.text { --h: 50px; height: var(--h); line-height: var(--h); border-width: calc(0.2 * var(--h)); border-style: solid; }
The only caveat is that since var() only works with custom properties, you need to
- declare a value in your own custom property and then
- any property that depends on this value must access the custom property through
var() .
But the fact that it works is itself very, very promising, and we can only hope that this new module will continue to evolve and be more widely implemented.