W3C home > Mailing lists > Public > www-style@w3.org > February 2012

Re: [css3-page][css3-mediaqueries] Changing element styles on page breaks

From: Tab Atkins Jr. <jackalmage@gmail.com>
Date: Fri, 24 Feb 2012 10:17:30 -0800
Message-ID: <CAAWBYDBeUpW9_55=FJbw3g0AxdJv=8qwP7A2SxgGwJZHDju9Ug@mail.gmail.com>
To: Simon Sapin <simon.sapin@kozea.fr>
Cc: Brad Kemper <brad.kemper@gmail.com>, "www-style@w3.org" <www-style@w3.org>
On Fri, Feb 24, 2012 at 6:52 AM, Simon Sapin <simon.sapin@kozea.fr> wrote:
> Le 24/02/2012 00:28, Tab Atkins Jr. a écrit :
>> On Tue, Feb 21, 2012 at 8:20 AM, Brad Kemper <brad.kemper@gmail.com>
>> wrote:
>>>
>>> If I can set a separate color to the first line of a span of text,
>>> why can't I also set a separate color to a the part of an inner
>>> span within the first line?
>>
>>
>> Because the well-behaved pseudo-elements are leaf nodes, while
>> ::first-line either has descendants (and thus the box-tree is no
>> longer a tree, as elements have two parents), or is broken up and
>> nested tightly inside of elements (in which case it's a leaf node).
>>
>> Depending on how Web Components handle selectors, we may eventually
>> have well-behaved non-leaf pseudo-elements, but they don't exist
>> yet.
>
> I don’t understand the part about elements having two parents. Could you
> explain a bit more?
>
> As I understand it there are two box trees for document. The first one is
> "before layout" and is built from the element tree as described in 9.2 of
> css21. The other one is "after layout" and has page boxes, line boxes etc. A
> box from the first tree may have been fragmented into multiple boxes in the
> second tree, but it’s still a tree. In that tree, line boxes do have
> descendants.

Properties are applied to elements, and are then copied over into the
boxes those elements generate.  (Or, alternately, properties are
applied to boxes, but assigned according to the elements that
generated them - the two formulations are equivalent.)

Take the following simple example, with manual line-breaking inserted:

<p>I'm a short paragraph.  <span>I only
have a few lines.</span></p>

There are two pseudo-documents you can consider that this desugars
into with ::first-line:

1)
<p><::first-line>I'm a short paragraph. <span>I only</span></::first-line>
<span>have a few lines.</span></p>

2)
<p><::first-line>I'm a short paragraph.
</::first-line><span><::first-line>I only</::first-line>
have a few lines.</span></p>

In the first, the <span> is a child of the ::first-line.  In the
second, it's the opposite.  Which structure you pick is potentially
important for various things, because some properties rely on the
element-tree to determine how to build the box-tree, and will produce
different results in the above two cases.

The tiny handful of properties that ::first-line is allowed to have is
deliberately chosen to only contain ones where you can't tell the
difference between the above two scenarios.  This allows authors to
pretend that they have the first structure (which is simpler to think
about), while implementations actually use the second structure (which
avoids breaking things based on properties on the <span>).  If you
tried to *force* the first structure (by declaring that the first part
of the <span> is a child of the ::first-line), you get a *lot* of
things potentially going wrong.

~TJ
Received on Friday, 24 February 2012 18:18:23 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 17:20:51 GMT