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 some best practices for preventing a counter from being updated on every page refresh in PHP?
- How can PHP be utilized to allow visitors to preview mp3 tracks before downloading them, without having background sound playing on the webpage?
- How can the order of PHP code execution, particularly in relation to headers, affect the functionality of passing objects between files?