This question already has answers here:
Alternate rows in one column only - CSS
                                
                                    (4个答案)
                                
                        
                                9个月前关闭。
            
                    
我有一些数据表。该表的第一列设置为粘性。现在我想要的是仅在第一列中每行的替代颜色。

这是我当前正在处理的表。

<div class="table-responsive">
    <table class="table table-bordered table-striped">
        <thead>
            <tr>
                <th colspan="1"></th>
                <th colspan="4"></th>
                <th colspan="3" style="text-align: center">%Penetration</th>
            </tr>
            <tr>
                <th scope="col">Action</th>
                <th scope="col" *ngFor="let tableHeader of this.tableHeaders">
                    {{ tableHeader }}
                </th>
            </tr>
        </thead>
    <tbody>


th:first-child,
td:first-child {
    margin-left: -1px;
    position: sticky;
    left: -1px;

}

td:first-child {
    background-color: white;
}



我试过了

td:first-child > td:nth-child(even){
    background-color: blue;
}

最佳答案

尝试这个

tr:nth-child(even) > td:first-child {
    background-color: blue;
}


这是示例https://codepen.io/anon/pen/QRLVoY

关于css - 设置第一列的备用行颜色,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55981099/

10-11 13:42