CSS selectors that should exist, but don't

edited February 2007 in Style Development
We have the child selector (#parent > #child) adjacent sibling selector (div + div). Why isn't there also a parent selector (#child < #parent) and previous sibling selector (div - div)? Sometimes the element you want to style has a child with an id you could use, and avoid a long string of "table > tbody > tr > td > table > tbody > tr > td > p" etc.


  • Yeah, those would definitely be useful for userstyles on sites with horrible HTML code. I've wished for those many times :) My only guess is that it's harder to code (for UA developers), and/or it's just not very common to ever have to use those...I dunno. I think Javascript and XPath have a way of selecting the parent based on a child, but not sure about the previous sibling one. Could come in handy for CSS though, that's for sure.
  • This guy sounds like he knows what he's talking about. Essentially, it'd be hard to implement because the browser wants to do CSS while parsing the document, so that means looking forward only.
  • There have been several situations where I've wished for selectors like those above. Fortunately I'll be able to solve one of them (element before :last-child) with CSS3 and :nth-last-child(1).
Sign In or Register to comment.