1

I have an to write a selector similar to:

div#content > section (.left > img) + .left

but obviously the parenthesis are ignored. How should I rewrite this? Or it isn't possible in plain CSS?

BoltClock
  • 630,065
  • 150
  • 1,295
  • 1,284
linkyndy
  • 14,398
  • 14
  • 96
  • 180

4 Answers4

2

No, you can't select something in CSS based on what it contains, which is essentially what you are attempting in the parentheses.

It's best explained by this question on SO.

Community
  • 1
  • 1
Nate B
  • 6,246
  • 23
  • 23
1

What your trying to do is not possible at least not as of the latest css3 spec.

If your not wanting to add via the server, maybe a bit of jQuery?

See this fiddle as it does what you want very easily

http://jsfiddle.net/4qZpc/2/embedded/result/ - results!

Grab the code: http://jsfiddle.net/4qZpc/2/

Tim Wickstrom
  • 4,396
  • 2
  • 18
  • 31
0

How about giving the section an id (assuming you have multiple sections) and then doing something like:

#content-section img + .left

I'm not entirely sure what effect you're trying to achieve here, but if there isn't a particular case where a .left element directly follows an img other than here, you should be safe.

Alternatively, if you have nested .left elements, you could do:

#content-section img + .inner-left
U-DON
  • 1,996
  • 11
  • 13
  • I wanted not to use additional ids...I hoped it can be resolved only with selectors and existing classes. – linkyndy Dec 06 '11 at 20:19
0

You'd have to add server-side an .image_in_it class on each element with .left class if it contains an img element.

<div id="content">
    <section>
        <div class="left image_in_it">
            <img src="" alt="">
        </div>
        <div class="left">
        </div>
    </section>
</div>

and then div#content > section > .left.image_in_it + .left would select any .left directly following .left.image_in_it

FelipeAls
  • 20,411
  • 7
  • 49
  • 71
  • I wanted not to use additional ids...I hoped it can be resolved only with selectors and existing classes. But thank you anyway! – linkyndy Dec 06 '11 at 20:44