我在子表上有tr表我不想应用悬停和斑马条纹,下面是我的代码不能正常工作,子表显示悬停和斑马条纹:
<table class='zebrastrip'>
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
<tr>
<table class='atable'>
<tr>
<td>5</td>
<td>6</td>
</tr>
<tr>
<td>7</td>
<td>8</td>
</tr>
</table>
</tr>
</table>
.atable tr:nth-child(2n-1){
background-color:#FFFFFF;
}
.atable tr:hover{
background-color:#FFFFFF;
}
.zebrastrip tr:nth-child(2n-1){
background-color:#f9f9f9;
}
.zebrastrip tr:hover{
background-color:#fce4cc;
}
由于
答案 0 :(得分:1)
固定代码的小提琴:http://jsfiddle.net/r3eAn/
修正了HTML:
<table class='zebrastrip'>
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
<tr>
<td colspan="2">
<table class='atable'>
<tr>
<td>5</td>
<td>6</td>
</tr>
<tr>
<td>7</td>
<td>8</td>
</tr>
</table>
</td>
</tr>
</table>
修复内部表背景的CSS总是#fff:
内部表格样式的优先级更高
内部表定义的背景
.zebrastrip tr:nth-child(2n-1){
background-color:#f9f9f9;
}
.zebrastrip tr:hover{
background-color:#fce4cc;
}
.zebrastrip .atable{
background: #FFFFFF;
}
.zebrastrip .atable tr:nth-child(2n-1){
background-color:#FFFFFF;
}
.zebrastrip .atable tr:hover{
background-color:#FFFFFF;
}