W3C home > Mailing lists > Public > www-archive@w3.org > January 2009

cycle() proposal

From: L. David Baron <dbaron@dbaron.org>
Date: Thu, 8 Jan 2009 14:35:44 -0800
To: www-archive@w3.org
Message-ID: <20090108223544.GA9864@pickering.dbaron.org>
Attached.

-David

-- 
L. David Baron                                 http://dbaron.org/
Mozilla Corporation                       http://www.mozilla.com/

attached mail follows:


I'd like to resurrect an old proposal for addition to css3-values [1]:
  http://lists.w3.org/Archives/Public/www-style/1999May/0067
  http://lists.w3.org/Archives/Public/www-style/1999Jun/0026
This is particularly useful for styling HTML's UL and EM elements.

Proposed text that could be used in the specification is the following:

=====

The cycle() expression allows descendant elements to cycle over a list
of values instead of inheriting the same value.  The syntax of the
cycle() expression is:

  cycle( <value> [, <value> ]*)

where <value> is a CSS value that is valid where the expression is
placed.  If any of the values inside are not valid, then the entire
cycle() expression is invalid.

The value returned by cycle() must be determined by comparing the
inherited value I (the computed value on the parent, or, for the root,
the initial value) to the computed values C[n] returned by the n-th
argument to cycle().  For the earliest C[n] such that C[n] == I, the
value returned by cycle is C[n+1].  However, if this C[n] is the last
value, or if there are no C[n] that equal I, the computed value of the
first value is returned instead.

Example 1:

  /* make em elements italic, but make them normal if they're inside
     something that's italic */
  em { font-style: cycle(italic, normal); }

Example 2:

  /* cycle between markers for nested lists, so that the top level has
     disk markers, but nested lists use circle, square, box, and then
     (for the 5th list deep) repeat */
  ul { list-style-type: disk; }
  li > ul { list-style-type: cycle(disk, circle, square, box); }

=====

It could also be used in other interesting ways -- probably some bizarre
ones that I haven't even thought of yet.  Although I admit I have
already thought of:
  list-style-type: cycle(cycle(disc,disc,circle,circle), cycle(disc,circle),
                         cycle(square,square,box,box), cycle(square,box));
Understanding this is left as an exercise to the reader.

-David

-- 
L. David Baron                                <URL: http://dbaron.org/ >
           Technical Lead, Layout & CSS, Mozilla Corporation

Received on Thursday, 8 January 2009 22:36:27 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 7 November 2012 14:18:20 GMT