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 steps to properly include and use external libraries like SimpleHTMLDOM in PHP scripts?
- What are the differences between using localhost for database connections and header redirects in PHP?
- What are the potential security risks of storing customer names and profile pictures as cookies in PHP?