Arithmetic in <length> values

Noel Akins wrote to <www-style@w3.org> on 1 March 2003 in "suggestions"
(<mid:5.2.0.9.0.20030301222803.01e2a148@pop3.arkansas.net>):

> I have a suggestion for an addition to the Height and
> Width properties as it applies to the box model. I would like to see the
> following.
> 
> Basically put: Height: 100% - Xpx;
> 
> I was told that this had been suggested before. Well, I'll suggest it again.

Yes, arithmetic for <length> values has surfaced as a suggestion several
times.

If arithmetic is allowed, it should be allowed anywhere that <length> is
allowed. The problem is that in some declarations, several <length> terms
occur in sequence. Consider the following three rule sets.

foo {
    margin: 10em -5%;
    }

foo {
    margin-top: 10em;
    margin-bottom: 10em;
    margin-right: -5%;
    margin-left: -5%;
    }

foo {
    margin-top: 10em - 5%;
    margin-bottom: 10em - 5%;
    margin-right: 10em - 5%;
    margin-left: 10em - 5%;
    }

Which of the latter two should be equivalent to the first? To solve this
ambiguity, a proposed grammar follows, with <basic-length> representing the
current form of <length>.

<length>
    = <arithmetic-length> | <basic-length>

<arithmetic-length>
    = ( <basic-length>+ )

<percent-length>
    = <percent> | <length> | ( [<percent> | <basic-length>]+ )

To express the arithmetic, the given grammar uses the unary operator that is
optional with each <length>. Thus space is forbidden between the operator
and the following number. If it is felt necessary to permit the space, use
the following productions.

<arithmetic-length>
    = ( [<basic-length> <pom>]+ <basic-length> )

<percent-length>
    = <percent> | <length>
      | ( [[<percent> | <basic-length>] <pom>]+
          [<percent> | <basic-length>] )

<pom>
    = "+" | "-"

Received on Tuesday, 4 March 2003 06:13:30 UTC