Re: Selector "on presence of"

[I quote Daniel here, but Douglas said similar things of equal truth and my
response takes his comments into account. First I discuss the points raised,
then I propose a modification which would be easier to implement]

A quick subset of my original suggestion is:
>> BODY.letter:conditional(BODY IMG.logo) { margin-top: 2em; }
>> applies to BODY elements with class "letter" when there is an element IMG
>> with class "logo" in the document tree.


Daniel Glazman wrote:
> If you take a look at actual CSS 2 selectors, you'll see that they are
> designed so the browser does not have to deal with the complete parse
> treee of the document. Implementors have already refused extensions of
> selectors because of this lack of a full parse tree and for
> 'performances' reasons.

I fully realise that this idea is dramatically more complicated to implement
than anything so far present in CSS specs. As I said to Simon, in his case
and in all cases I have so far met there are quicker ways of achieving the
same effect. However, I am sure there are cases where (as far as the
_stylesheet_ author is concerned) this would be much simpler/easier.

Daniel's opinion:
> 1) lack of a parse tree: this is implementation problem and should
> not constrain the spec...
> 2) performances: even my Pilot is able to browse the web and the very
> first Sega or Nintendo is more powerful than my pc !

I agree, and will do so until the day that I decide to write my own
renderer.

> So: your proposal is interesting but you can be 100% sure that
> implementors will refuse it for implementation reasons.
Ah... I see the postprocessor implemented in your sendmail is still
working... :-)

Unfortunately, you are right. However, I think most things which are going
to be in CSS3 are going to be hard to implement. Take, for example, Eric
Sink's "complex page patterns" suggestion (which looked very interesting,
BTW).

> Last thing: pseudo-elements do not imply a condition on the target
> element in CSS2. Your proposal breaks that.
This is a pseudo-class. ("A:hover" is certainly a condition - it only
applies to an A elements that have the pointer over it).


An improvement over my idea is to drop the full parse tree search. Instead,
the pseudo-class only checks descendants. (If you read the original idea,
then basically you drop the ":main-selector" thing and infer it at the
beginning of _all_ of the checked selectors).

Examples to make it clearer, in order of clarity (clearest first):

BODY.letter:contains(IMG.logo) { margin-top: 2em; }
/* applies to BODY elements with class "letter" when it contains an element
IMG with class "logo". */

BODY H1 { font-size: 200%; }
BODY:contains(H2) H1 { font-size: 400%; }
/* H1 is twice as big when there is an H2 in the document. */

BODY P:contains(IMG) { text-align: center; }
/* Centers paragraphs that contain images. */

BODY FORM:contains(INPUT[type=submit]) BUTTON.javascriptsubmit
display:none; }
/* Hides BUTTON elements of class "javascriptsubmit" when they are contained
by a FORM element which contains an INPUT element with the "type" attribute
equal to "submit". */

BODY:contains(BLOCKQUOTE P IMG.signature):before { display: block;
background: white; color: red; border: thin solid black; content: "This \
contains a signed document!" }
/* Adds a bordered white box containg the text "This contains a signed
document!" at the top of the canvas when the body element contains a
blockquote containing a paragraph containing an image with class signature.
*/


/* And now a reason not to have this feature: */

P.message:after { content: " nowhere"; }
DIV.special BLOCKQUOTE:contains(CITE A.author:focus) + P.status
SPAN.link:after { content: " an author"; }

/* assume the following document:

<BODY>
   <DIV CLASS=special>
      <BLOCKQUOTE>
         <P>We now have to consider
<CITE><A class=author href="...">Darwin</A></CITE>'s
            book.</P>
      </BLOCKQUOTE>
      <P CLASS=status>
         (<SPAN class=link>That is a link to</SPAN>.)
      </P>
   </DIV>
</BODY>


Then it would normally render as:

  We now have to consider Darwin's book.
  (That is a link to nowhere.)

But if Darwin's name has the focus, then the text should change to:

  We now have to consider Darwin's book.
  (That is a link to an author.)

*/

Now. About CSS not becoming a programming language...
--
Ian Hickson
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12   Info: www.geekcode.com
GIT/M/S d->-- s+: a--->? C++(+++)>$ U>*++++ P L+>+++++ E(+)>+++ W+++ N(+) o?
K? w@ O- !M V- PS+ PE- Y+ PGP>+ t 5+++>++++ X- R+(+++) tv b++(+++) DI++
D++(---)>++++ G>+++ e(*)>+++++ h!()(--) !r y?
------END GEEK CODE BLOCK------

Received on Friday, 5 June 1998 18:42:58 UTC