CSS has the +
selector which selects a sibling immediately following an element. As discussed in this question, there is no similar -
selector for selecting the sibling that immediately precedes an element.
What are the reasons for not having a -
selector that selects the preceding sibling? More specifically, what are the technical limitations, if any, with having a browser do this?
Let's suppose for the sake of argument that I'd like to be able to write code like this:
<style>
p:hover, img:hover + p {
background-color: yellow
}
img:hover, p:hover - img {
outline: solid 2px yellow
}
</style>
...
<img src="image.png"/>
<p>Description of image 1</p>
<img src="image1.png"/>
<p>Description of image 2</p>
Ideally, I wouldn't have to write any Javascript and I wouldn't have to restructure my HTML by (for example) wrapping the pairs in common divs. Can anyone indicate a technical reason why I can't select preceding siblings in CSS?