How come these two don’t come out equivalent? The first one shows a green row, while the second doesn’t. The only difference is in html c Furthermore, what is the specificity of the nth-child selector?
<!DOCTYPE html>
<html>
<head>
<title>Stripe Test</title>
<style type='text/css'>
tr:nth-child(2n+1)
{
background-color: red;
}
tr.c
{
background-color: green;
}
</style>
</head>
<body>
<table class='stripe'>
<tr class='c'>
<td>one</td>
</tr>
<tr>
<td>two</td>
</tr>
<tr>
<td>three</td>
</tr>
</table>
</body>
</html>
-vs-
<!DOCTYPE html>
<html>
<head>
<title>Stripe Test</title>
<style type='text/css'>
tr:nth-child(2n+1)
{
background-color: red;
}
tr .c
{
background-color: green;
}
</style>
</head>
<body>
<table class='stripe'>
<tr class='c'>
<td>one</td>
</tr>
<tr>
<td>two</td>
</tr>
<tr>
<td>three</td>
</tr>
</table>
</body>
</html>
tr.c(no space)` is a table row of class c.tr .c(with space) is a table row, followed by some OTHER unspecified tag with class c.The space implies a parent/child relationship. Since you’ve got the
cclass ON the tr tag itself, there is no child below thetrthat has acclass.