1

Is there anyway to specify a class after a pseudo element? For example, I want to find the :last-childof the parent - and if that child has x-class, style accordingly. With SCSS, this would be relatively easier, but the project I'm working on doesn't use SASS.

Any ideas?

Here's what I was trying to do...which is obvs wrong:

form .entry-form-wrap :last-child.nested-tmpl-inner

HTML is too complex to post, but I've included a general block of code to give you an idea of the flow:

<form>
    <div class="entry-form-wrap">
        <div class="some-class" />
        <div class="some-class" />
        <div class="some-class nested-tmpl-inner" />
    </div>
</form>
3
  • 1
    You should post some relevant html as well.
    – Andy G
    Commented May 29, 2014 at 18:06
  • 2
    You cannot specify a class selector after a pseudo-element, since pseudo-elements cannot have classes, but you can specify a class selector after a pseudo-class (which is what :last-child is), because simple selectors can be arranged in any order in a chain (with the exception of type/universal always appearing first). The selector that you have is valid, but a selector like ::after.class would be invalid. This is why the distinction between pseudo-elements and pseudo-classes is so important.
    – BoltClock
    Commented May 29, 2014 at 18:16
  • Agh - nice! Makes complete sense. Commented May 29, 2014 at 18:24

1 Answer 1

3

It's not obvs wrong. You can specify a class right after the pseudo, like :pseudo.class.

Check this fiddle: http://jsfiddle.net/fYy4T/

2
  • Interesting...wasn't working for me. Let me see if I have an error somewhere. Commented May 29, 2014 at 18:13
  • My problem wasn't the CSS persay, it was that I have hidden div's below the class I'm trying to target. So :last-child is not getting triggered... Commented May 29, 2014 at 18:32

Not the answer you're looking for? Browse other questions tagged or ask your own question.