Scss, nth-child & :not() selector

Viewed 9274

I'm a bit new to scss and I have this basic style for rows in my rows container.

.rows-container{
    border-bottom:2px ridge grey;
}
.row{
    height:30px;width:100%;

    &:hover div{
        background-color:lightgrey;
        }
    &:nth-child(odd){
        background: white;
        }
    &:nth-child(even){
        background: #e0e0e0;
        }
}

pretty straight forward with the following html: i have left out some html that is not important.

<div class="rows-container">
    <div class="row></div> //white
    <div class="row></div> //grey
    <div class="row></div> //white
    <div class="row></div> //grey etc...
</div>

But now I have added child rows

<div class="rows-container">
    {{each rows}}
        <div class="row"></div>           //parent row

        {{each childs}}
        <div class="subitem"></div>   //several rows from the same table which have a parent_id connected to the current row.
        {{#each}}

    {{#each}}
</div>

I am planning to toggle the subitems on click. But when no subitems are visible (subitems have a color of their own), the '.rows' odd/even is messed up. Now I think this is caused because the nth-child odd/even is calculated on all rows/subitems in the container, and not just the .row(s). Is there a way to odd/even style the .rows, but exclude .subitems from the odd/even rotation? I was thinking that maybe there is a way to use :not() in scss, but so far I have not succeeded.

2 Answers
Related