1

Possible Duplicate:
Complex CSS selector for parent of active child

This is my markup:

<ol class="wp-paginate">
    <li><span class="title"></span></li>
    <li><span class="page current">1</span></li>
    <li><a href="http://localhost/page/2/" title="2" class="page">2</a></li>
    <li><a href="http://localhost/page/2/" class="next">»</a></li>
</ol>

And I want to change the background-position property of the li element that has a span child with the class current. In this case, the second list item.

I do consider myself proficient with CSS, but I really cannot think of how to do that. Maybe there isn't a way, or I'm just having a brain fart.

Thanks!

Community
  • 1
  • 1
James Dawson
  • 5,309
  • 20
  • 72
  • 126
  • this is not achievable using css.Use jquery to do this. – Maverick Jan 29 '12 at 01:12
  • At least not yet, soon (hopefully :) you'll be able to do this: `ul li! span.current {properties here will style the li, not the span}`. I was pretty sure it was `$li`, not `li!` (Paul Irish wrote about it on G+) but according to this it's not: http://dev.w3.org/csswg/selectors4/#subject. You could also try this jQuery plugin: http://www.jqueryrain.com/2012/01/use-css4-parent-selector-right-now-with-cssparentselector-js/ – powerbuoy Mar 27 '12 at 02:08

3 Answers3

0

There's no way you can do this in CSS. You'll have to resort to Javascript for that.

If you really want to do this in pure CSS, you'll have to move the current class onto the lis themselves.


Side note: In CSS4 you'll be able to do the following:

.wp-paginate $li span.current { }

Needless to say, not a single browser currently supports this.

Joseph Silber
  • 214,931
  • 59
  • 362
  • 292
0

No, that's not currently possible with CSS. See: Is there a CSS parent selector?

You will need to either edit the html output, or perform the selection via JQuery.

Community
  • 1
  • 1
Matthemattics
  • 9,577
  • 1
  • 21
  • 18
0

Its nearly impossible with javascript.

Using jQuery

$("li").each(function() {
  if($(this).find("span.current").length > 0) {
    $(this).css("backgroundPostion", "top left");  
  }
});
Starx
  • 77,474
  • 47
  • 185
  • 261