我试图在表格行中的特定单元格上放置上边框。我正在使用以下 css 这样做:
table.v65-productDisplay > tbody > tr:nth-child(5n+1) > td:nth-of-type(1),
table.v65-productDisplay > tbody > tr:nth-child(5n+1) > td:nth-of-type(3),
table.v65-productDisplay > tbody > tr:nth-child(5n+1) > td:nth-of-type(5)
{border-top:1px solid #d6d5d5; }
这个 css 非常适合第三个和第五个 child ,但出于某种我不知道的原因,当我为第一个 child 添加边框时,它跨越了整个表格行。这只发生在 chrome 浏览器中。
我错过了什么?我已经尝试了所有我能想到的配置。
您可以在我的网站上实时查看这种奇怪现象: http://www.yandasmusic.com/Guitars-s/1820.htm
最佳答案
这是因为您要定位的表包含在另一个具有相同类名的表中:
<table width="100%" border="0" cellspacing="10" cellpadding="10" class="v65-productDisplay">
<tbody>
<tr>
<td> <!-- this td is also targeted -->
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="v65-productDisplay">
<tbody>
<tr>
<!-- ... -->
所以,这条规则:
table.v65-productDisplay > tbody > tr:nth-child(5n+1) > td:nth-of-type(1)
匹配包裹第二个嵌套表格的 td
,给它上边框。
关于使用 :nth-child, 选择表格单元格的 css 边框:chrome 中的第 n 个类型选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27450468/