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
- Are there any PHP built-in functions or classes that can efficiently convert microtime values to date and time formats without reinventing the wheel?
- What are common pitfalls when using preg_match in PHP for pattern matching?
- In the context of the PHP forum thread, how could the script be adapted to group events based on both date and group, as requested by the user?