-1

Ok here's my div structure

<div id="ad"></div>
<div id="campaign"></div>

I want the CSS basically to set a style to the "ad" div when it appears back to back to the campaign DIV. I know that #ad+#campaign will just target the 'campaign' div. Is there a way to write it so that I can target the ad div when they appear in the page in that structure?

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
Jason Tremain
  • 1,259
  • 3
  • 20
  • 35

1 Answers1

1

No. CSS currently lacks any feature for selecting an element based on anything that appears after it.

Selectors level 4 introduces ! which I think will allow you to:

!#ad + #campaign {}

… but it is someway past the bleeding edge for support at present.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • ...except for `:last-child`. – SLaks Mar 19 '13 at 14:45
  • http://dev.w3.org/csswg/selectors4/#subject – Quentin Mar 19 '13 at 14:51
  • Some parts of CSS 3 are stable. If those modules are to get new features, they need to increment the level number to something. – Quentin Mar 19 '13 at 14:51
  • There are other parts of CSS which have having their 4th level developed: http://dev.w3.org/csswg/css4-background/ – Quentin Mar 19 '13 at 14:54
  • @SLaks: And `:only-child`. – BoltClock Mar 19 '13 at 15:07
  • @Lotus: Nobody really knows what to call the various levels of CSS beyond CSS2.1. It would be nice if everybody were to follow the intended naming scheme and refer to individual CSS modules by their names and their levels and to CSS the language by simply "CSS", but the simple reality is that people are going to use terms like "CSS3" and "CSS4". The fact that spec URLs begin with "css-" doesn't really help matters (although they're moving to canonicalize them to "css--" - with an example being [css-text-decor-3](http://www.w3.org/TR/css-text-decor-3)). – BoltClock Mar 19 '13 at 15:09