【问题标题】:Remove border lines and assigning color for alternate table rows?删除边框线并为备用表格行分配颜色?
【发布时间】:2019-05-29 22:56:40
【问题描述】:
【问题讨论】:
标签:
html
css
angular
typescript
【解决方案1】:
交替行颜色:
tr:nth-child(odd) { background-color:#eee; }
tr:nth-child(even) { background-color:#fff; }
【解决方案2】:
试试这个……
table {
border-collapse: collapse;
}
table, th, td {
border: 1px solid black;
}
table, th, td {
border: 1px solid black;
}
tr:nth-child(odd){
background-color: gray;
}
tr:nth-child(even){
background-color: cyan;
}
HTML
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>Peter</td>
<td>Griffin</td>
</tr>
<tr>
<td>Lois</td>
<td>Griffin</td>
</tr>
<tr>
<td>Lois</td>
<td>Griffin</td>
</tr>
<tr>
<td>Lois</td>
<td>Griffin</td>
</tr>
<tr>
<td>Lois</td>
<td>Griffin</td>
</tr>
</table>
【解决方案4】:
要删除边框,请在您的 css 中添加以下内容:
table tr,
table td {
border: 0;
}
要为每隔一行添加一种颜色,请使用 nth-child 选择器:
table tr:nth-child(even) {
background-color: grey;
}
您还需要从您的 css 中删除以下部分:
.mat-table-sticky:first-child {
border-right: 1px solid #e0e0e0;
}
.mat-table-sticky:last-child {
border-left: 1px solid #e0e0e0;
}
【解决方案5】:
请添加如下CSS代码:
.mat-table-sticky:first-child {
border-right: none;
}
td.mat-cell,
td.mat-footer-cell,
th.mat-header-cell {
border: none;
}
tr.mat-row:nth-child(2n+1) {
background-color: #EFEFEF;
}
tr.mat-row:nth-child(2n) {
background-color: #C5C4C4;
}