开发者

table:last-child not working

I have something like this

<table>
  <tr>
    <td>First table</td>
  </tr>
</table>

<table>
  <tr>
    <td>Second table</td>
  </tr>
</table>

And the following CSS

table {
  margin-bottom:40px;
}
table:last-child {
  margin-bottom:0px;
}

But the s开发者_JAVA技巧econd table still gets margin-bottom applied. Wat do?


@Quentin is right that your code does not reproduce your described problem.

I'm going to guess what the problem is.

table:last-child does not mean "the last table in the parent element".

It actually means "the last element in the parent element if it's a table".

For example, given this HTML table:last-child will not select anything:

<div>
    <table>
        ..
    </table>

    <table>
        ..
    </table>

    <div>I'm the last child</div>
</div>


You could try to use table:last-of-type.

Both selectors won't work in IE8 and lower

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜