Skip to content

Instantly share code, notes, and snippets.

@kitgrose
Created December 11, 2012 08:58
Show Gist options
  • Save kitgrose/4257140 to your computer and use it in GitHub Desktop.
Save kitgrose/4257140 to your computer and use it in GitHub Desktop.
Weird WebKit CSS bug
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
tr > * {
padding: 1em;
}
tr:nth-child(even) td {
background-color: red;
}
</style>
</head>
<body>
<table cellpadding="0">
<tr>
<th>1</th>
<th>2</th>
<th>3</th>
<th>4</th>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
</body>
</html>
@kitgrose
Copy link
Author

This is definitely the weirdest bug I've seen in WebKit. All four cells in the second table row should be red, but only the first two are.

The issue goes away if you remove the cellpadding attribute, or if you replace the first row with td elements instead of th ones. The issue doesn't affect nth-child(odd), only even (the mere existence of an odd CSS rule—even without any declarations—changes the behaviour). If you try to inspect either of the wrong-coloured elements, they redraw correctly.

If you add another row of standard cells, they're also treated as even, even though they're now in the third row.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment