This example shows in detail... The problem starts with:
.h:hover { background:red }
.h:hover ~ td { background:blue }
That works fine: the :hover
event selector triggers the following-sibling td
element. So, we can say that the ".h:hover
triggers ~ td
"... But, if the td
element has a backward occurrence, there is no selection.
PS: note that the rolspan
in the example causes a "layout with a td
following-sibling" where structure have a td
that is not following.
The only possibility is the #id
selector. So, why does CSS not offer some operator or construction to use #id
in that constraint?
SUB-QUESTION#1: is there any pure CSS solution?
(edit) Thanks @TylerH to show that sub-question#1 is not a duplicate (!).
The point here is the #id
selector in a trigger-event context.
Why CSS3 or CSS4 or "?" standards are not using #id
for this kind of application. Are there some standard about CSS events and a better control for manage them?
We know that there is no "previous sibling" selector, and this is an understandable problem with parse algorthims. But "find #id
" algorithm (no matter if next or previous!) is so simple and so fast, there are no "parse problem" to adopt #id
in a kind of "trigger selector".
SUB-QUESTION#2: there are a standardization iniciative (at CSS WG?) to do some workaround to the problem, using #id
as triggered selector?
PS
The HTML label
tag and for
attibute deal with similar problem. A <label for="for">
not need Javascript to triggers (by click event) its correspondent <input type="checkbox" id="for">
checked... So, we can imagine an on-mouse-over correspondent event triggering in the same way,
label#from1:hover <OPERATOR> #for1 { ...do something... }
at a typical HTML form like this,
<div id="for1">
<input type="checkbox" id="mycheck"/>
<span></span>
</div><!-- tag input BEFORE tag label-->
<label id="from1" for="mycheck">Label for my styled "checkbox"</label>