Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tablerows hover with table even/odd styled via CSS

Tags:

html

css

even/odd styles set on tablerows but hovering of table rows don't work .
Try it on : http://jsfiddle.net/w7brN/

CSS style :

#table_even tr:hover { background-color:#fffbae!important; } /* hovering */

#table_even tr:nth-child(odd) td { background-color:#fbfbfb } /*odd*/
#table_even tr:nth-child(even) td { background-color:#e8ecee } /* even*/

HTML Codes:

<table id="table_even" style="width: 100%">
    <tr>
        <td>##</td>
        <td>##</td>
    </tr>
    <tr>
        <td>##</td>
        <td>##</td>
    </tr>
    <tr>
        <td>##</td>
        <td>##</td>
    </tr>
</table>

how can be solve ?

like image 457
Root Avatar asked Jan 28 '26 23:01

Root


1 Answers

You need to re-order the CSS and add the <td> like so this:

   #table_even tr:nth-child(odd) td {
    background-color: #fbfbfb
} /*odd*/
#table_even tr:nth-child(even) td {
    background-color: #e8ecee
} /* even*/
#table_even tr:hover td {
    background-color: #fffbae;
} /* hovering */

Otherwise the nth-child rules will always have precedence over the hover, aswell as you added the background-color to the <tr>, not the <td>s before.

like image 99
Henrik Ammer Avatar answered Jan 30 '26 16:01

Henrik Ammer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!