Since there is no parent selector, you won't be able to do this with pure CSS. Even if you gave all the .x
elements that have .y
children an additional class name, you would still be unable to select the last among those elements, because there is no last-of-class selector.
You'd have to programmatically find the last .x
containing a .y
to add an extra class name for you to select in CSS.