1

I have a simple HTML table generated with PHP from a database where in some cases one cell spans over more than one row. As a simple example:

<table>
  <tr class ="highlightRow">
    <td>Cell 1</td>
    <td rowspan="2">Cell over more rows</td>
  </tr>
  <tr class ="highlightRow">
    <td>Cell 2</td>
  </tr>
</table>

I highlight the row the mouse is over with a simple CSS rule:

.highlightRow {
    background-color:       #FFF;
}
.highlightRow:hover {
    background-color:       #EEE;
}

I can not find any solution (that is CSS only) to highlight 'Cell over more rows' when the mouse hovers over 'Cell 2'.

Brian Tompsett - 汤莱恩
  • 5,195
  • 62
  • 50
  • 120
Ardor
  • 13
  • 5

2 Answers2

0

I had meet same problems in my projects.We cannot do it.That is why most of all developers perefered jquery DOM traversing methods(parent(),child(),sibling(),next(),prev(),After(),etc..,)

Reference: Is there a CSS parent selector?

Conclusion is :there is no option in CSS for select the parent.we can with javascript help.

**we love coding..*

Community
  • 1
  • 1
iyyappan
  • 727
  • 3
  • 10
0

I don't know if this will satisfy your need, but have a look at my solution

.highlightRow {
    background-color:       #FFF;
}

.highlightRow:hover{
    background-color:       #EEE;
}


table:hover .include{
    background-color:       #EEE;
}
<table>
  <tr class ="highlightRow">
    <td>Cell 1</td>
    <td rowspan="2" class="include">Cell over more rows</td>
  </tr>
  <tr class ="highlightRow">
    <td>Cell 2</td>
  </tr>
</table>

Thr trick is to highlight .include cell every time the table has been hovered and add some rule to highlight tr everytime it's hovered.

StaleMartyr
  • 748
  • 5
  • 18
  • If we hover cellover more rows means same itself also bg color changed..that is not correct requirement. – iyyappan Dec 23 '15 at 10:30
  • that is a appropriate solution in case 'cell over more rows' should be highlighted in every case. In my case 'cell over more rows' should only be highlighted if one of the adjacent rows is selected, considered that the table goes on after those two rows. – Ardor Dec 23 '15 at 10:40