Re: Selector "on presence of"

> Would it make sense to have a selector that makes the rules apply only
> if a certain other element is present/not present?
> This could be laid out as a letter, no problem, but if the sender wanted
> to add something like a company logo, the layout would need some
> corrections, which could be made in a special rule which would only
> apply if a IMG.logo was present.

Why not just apply the rule to the IMG.logo element? (position it, etc).

However, I do like the idea of a selector which applies to elements matching
some condition based on other information gathered from the tree.

What about this: A pseudo-class like the :lang() pseudo-class, which accepts
as parameter a css selector. If the selector given as a paramter applies to
anything, then the rule applies to the main selector.

Eg:

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.

Other example:

BODY H1 { font-size: 200%; }
BODY H1:conditional(BODY H2) { font-size: 400%; }

H1 is twice as big when there is an H2 in the document.

This begs for another keyword - ':main-selector' or some such - which
matches the element(s) matched by the main selector.

BODY P:conditional(:main-selector + IMG) { text-align: center; }

Centers paragraphs which appear before images.


BODY FORM:conditional(:main-selector > INPUT[type=submit])
BUTTON.javascriptsubmit { display:none }

Hides BUTTON elements of class "javascriptsubmit" when they are contained by
a FORM element which contains as a direct child an INPUT element with the
"type" attribute equal to "submit".


Alternative names instead of :conditional() might be
:condition()
:present()
:selector-present()



>(BTW: Is there a
>:first-page pseudo-class?)
Yes. IIRC, @page :first {}

--
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 Thursday, 4 June 1998 18:25:55 UTC