简体   繁体   中英

Odd table rows not highlighting

I have a table that highlights all the odd rows.

To do this, I just check what the row number is and apply the alt class to said row.

I then highlight the row on hover using a simple :hover in the CSS file.

It highlights the non- .alt rows perfectly, but not the alt rows.

Here is my CSS code:

.datagrid tr:hover, .datagrid tr.alt:hover {
    background-color:#497A43;
    color:#D3F0D4;
}

What am I doing wrong?

dont apply those cumbersome class changing methods. Instead use the css selector

.datagrid tr:nth-child(even):hover {background: #CCC}
.datagrid tr:nth-child(odd):hover {background: #FFF}

js fiddle

It works without needing the .alt selector.

See http://jsbin.com/ixokoj/2/edit

instead of

.datagrid tr:hover, .datagrid tr.alt:hover 

{


    background-color:#497A43;


    color:#D3F0D4;


}

use the following

.datagrid tr.alt:hover 

{

    background-color:#497A43;

    color:#D3F0D4;


}

The above will apply the background color and color to the rows which has class as "alt" and only when they are hovered.

Hope this helped.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM