If I understand your question correctly, something like the stuff below might work for you. I used the following HTML, based on your example:

<p>1st paragraph</p>
<p>2nd paragraph</p>
<h2>Some heading</h2>
<p>3rd paragraph</p>
<p>4th paragraph</p>
<p>5th paragraph</p>

and this CSS:

p              { color: green; }
h2 + p, p + p  { color: red; }

The first p before the h2 gets green text. All others are red. Which selectors are needed to style the elements after the h2 depends on your HTML.

This is not very nice - but it works. The basic idea is to use a generic selector for the special case and then override it with more specific selectors for the other elements.

The first rule targets all p elements. The second rule overrides this for

a) p elements that directly follow a h2 element (3rd p) and
b) for all p elements that have another p element as an adjacent
   sibling (2nd, 4th and 5th p).

According to the current draft for CSS3 selectors there may be a :nth-of-type selector which might be just the thing you're after. More on the new selectors can be found here:
  http://www.w3.org/TR/css3-selectors/#selectors

hope this helps,

Joergen


Am 30.08.10 13:12, schrieb Rick Gordon:
> Is there some way to address the first member of an adjacent sibling
> selector, as opposed to the last member?
>
> For example, if I wanted to address p tags immediately preceding an
> h2, how might I go about it? Thanks.
______________________________________________________________________
css-discuss [cs...@lists.css-discuss.org]
http://www.css-discuss.org/mailman/listinfo/css-d
List wiki/FAQ -- http://css-discuss.incutio.com/
List policies -- http://css-discuss.org/policies.html
Supported by evolt.org -- http://www.evolt.org/help_support_evolt/

Reply via email to