How can the CSS pseudo-class :nth-child() be applied to create alternating row colors in tables, as suggested in the W3C documentation?
To create alternating row colors in tables using the CSS pseudo-class :nth-child(), you can target every even or odd row and apply different background colors to them. This helps improve the readability and visual appeal of the table for users. By using the :nth-child() pseudo-class with the even or odd keyword, you can easily achieve this effect without the need for additional classes or JavaScript. ```css /* CSS */ tr:nth-child(even) { background-color: #f2f2f2; } tr:nth-child(odd) { background-color: #ffffff; } ```
Keywords
Related Questions
- What are the potential issues with using multiple MySQL queries in PHP, as seen in the code snippet provided?
- How can PHP be used to display multiple events with different colors in a calendar layout?
- How can PHP developers ensure that all database query results are properly displayed on a webpage without missing any entries?