我有一个简单的表,使用tr:nth-child(单数)来替换表中行的背景。
HTML
/*-----------#602 SAO Styles-----------------------------*/
/*---------SAO Global------------*/
.sao-pricing-table table {
border-collapse: collapse;
width: 80%;
margin: 0 auto;
background: #ffffff;
}
.sao-pricing-table table td {
height: 20px;
}
table.sao-table {
border-collapse: collapse;
}
/*-----Basic Title Cells---------*/
.sao-top-1 {
border: 0px;
background: #FFFFFF;
height: 40px;
width: 40%;
}
.sao-top-2 {
font-size: 16px;
text-shadow: 2px 4px 3px rgba(0, 0, 0, 0.3);
color: #FFFFFF;
border: 0px solid #a8b5b9;
background-color: #003869;
padding-top: 10px;
padding-bottom: 10px;
text-align: center;
height: 40px;
width: 30%;
}
.sao-top-2-title {
font-size: 110%;
}
.sao-top-2-type {
font-size: 120%;
}
.sao-top-2-price {
font-size: 100%;
}
/*------Gold Title Cells------*/
.sao-top-3 {
font-size: 16px;
text-shadow: 2px 4px 3px rgba(0, 0, 0, 0.3);
color: #FFFFFF;
border: 0px solid #a8b5b9;
background-color: #F2A405;
padding-top: 10px;
padding-bottom: 10px;
text-align: center;
height: ;
width: 30%;
}
.sao-top-3-title {
font-size: 110%;
}
.sao-top-3-type {
font-size: 130%;
}
.sao-top-3-price {
font-size: 100%;
}
/*----Regular Cells-----*/
#sao-table table {
border-collapse: collapse;
width: 100%;
}
th,
td {
padding: 0.25rem;
text-align: center !important;
border: 1px solid #ccc;
height: 20%;
}
tr.sao-zebra:nth-child(odd) {
background: #23282D !important;
}
.sao-feature {
text-align: left !important;
}
/* Checkmark Style-----*/
.sao-checkmark {
font-size: 125%;
color: #F2A405;
text-shadow: 2px 4px 3px rgba(0, 0, 0, 0.2);
}

<div class="sao-pricing-table">
<table class="sao-table">
<thead>
<tr>
<th class="sao-top-1">
</th>
<th class="sao-top-2">
<span class="sao-top-2-title">Some Text</span>
<span class="sao-top-2-type">More Text</span>
<span class="sao-top-2-price">Even More Text</span>
</th>
<th class="sao-top-3">
<span class="sao-top-3-title">Some Text</span>
<span class="sao-top-3-type">More Text</span>
<span class="sao-top-3-price">Even More Text</span>
</th>
</tr>
</thead>
<tbody>
<tr>
<th class="sao-feature">Text</th>
<td class="sao-detail">Text</td>
<td class="sao-detail">Text</td>
</tr>
<tr>
<th class="sao-feature">Text</th>
<td class="sao-detail">Text</td>
<td class="sao-detail">Text</td>
</tr>
&#13;
按原样,该表有3列。第n个子伪选择器使每隔一列变为黑色,而不是每隔一行。我做错了什么?编辑:建议的行跨度的示例不包括第n个子选择器,因此我没有看到它是如何相同的。有人能填补我吗?
答案 0 :(得分:2)
您的选择器中有一个空格,在:nth-child
tr.sao-zebra:nth-child(odd) {
background: #23282D;
}