W3C

Bert Bos | CSS3 – values

Values and units

Values and units

Values and units – contents

cm, mm, in en pt are unfortunately no longer useful on screen media. So far there is no replacement.

Explicit inheritance: inherit

(Level-2 feature)

a:visited {color: inherit}

The color of the parent, whatever it is

Reset to the initial value: initial

From the demo:

div.back { font-size: initial }

(May 2013: Safari ok, Konqueror OK, Chromium ok, Firefox ok, Opera no)

(In fact, for 'font-size' there are two other ways to achieve the same: 'medium' and '1rem'.)

Expressions: calc()

For calculations ( + - * / ) that depend on the current rendering

From the demo:

p.framed {
  border: 10px solid gold;
  padding: calc(2em - 10px) }
p.unframed {
  padding: 2em }

The two boxes have the same width

Calc() syntax

„+” and „-” must have spaces on both sides

Only values of the same type can be added: calc(1em + 2s) is wrong

Division (/) only by numbers: calc(100% / 10em) is wrong

Division by 0 is evidently not possible

(May 2013: FF ok, IE ok, Opera no, Safari 5 no, Safari 6 with prefix, Chrome ok)

Values out of range

The -1em is ignored here and the result is 2em:

div {
 padding: 2em;
 padding: -1em  /* ignored, must ≥ 0 */ }

but not here:

div {
 padding: 2em;
 padding: calc(0px - 1em) /* accepted */ }

(-1em is still impossible, the nearest valid value, 0, is used)

The '-1em' is caught as an error when the syntax is checked and the line is simply ignored. But calc() values can only be checked for the correct type (length, number, time…). The value depends, in general, on the element it is used on, and thus no attempt is made to check it except for division by 0. (Division by zero can be checked, because it only involves numbers, never units.)