What are the benefits of using CSS selectors like td:nth-child(even) for alternating row colors in a table?
Using CSS selectors like td:nth-child(even) allows for easy implementation of alternating row colors in a table without the need for additional classes or inline styles. This method simplifies the styling process and makes the code more maintainable. Additionally, it provides a clean and efficient way to achieve the desired visual effect. ```html <!DOCTYPE html> <html> <head> <style> table { width: 100%; border-collapse: collapse; } tr:nth-child(even) { background-color: #f2f2f2; } th, td { border: 1px solid black; padding: 8px; text-align: left; } </style> </head> <body> <table> <tr> <th>Header 1</th> <th>Header 2</th> </tr> <tr> <td>Row 1, Cell 1</td> <td>Row 1, Cell 2</td> </tr> <tr> <td>Row 2, Cell 1</td> <td>Row 2, Cell 2</td> </tr> <tr> <td>Row 3, Cell 1</td> <td>Row 3, Cell 2</td> </tr> </table> </body> </html> ```