Make css nth-child() only affect visible

前端 未结 2 1691
庸人自扰
庸人自扰 2021-02-11 13:57

Is there a way to only affect visible elements with this css?

table.grid tr.alt:nth-child(odd)
{
    background:#ebeff4;
}

table.grid tr.alt:nth-child(even)
{
          


        
2条回答
  •  星月不相逢
    2021-02-11 14:43

    I ended up using the solution Rodaine suggested in his comment, after the show/hide i do this:

    $('.alt:visible:odd').css('background', '#EBEFF4');
    $('.alt:visible:even').css('background', '#FFFFFF'); 
    

    In my case the setting of background broke my hover, this was solved with !important to make the hover background stick.

    table.grid tr.hover:hover
    {
        cursor:pointer;
        background:#D2E0E9 !important;    
    }
    

提交回复
热议问题