How can CSS be utilized to style HTML elements, such as tables, instead of using deprecated HTML attributes like bgcolor?
To style HTML elements like tables without using deprecated HTML attributes like bgcolor, CSS can be utilized by targeting the elements with specific classes or IDs and applying styles to them. This allows for more control over the design and layout of the elements, making the code cleaner and more maintainable. ```html <!DOCTYPE html> <html> <head> <style> .table-style { border-collapse: collapse; width: 100%; } .table-style th, .table-style td { border: 1px solid black; padding: 8px; text-align: center; } .table-style th { background-color: lightblue; } .table-style tr:nth-child(even) { background-color: #f2f2f2; } </style> </head> <body> <table class="table-style"> <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> </table> </body> </html> ```
Keywords
Related Questions
- What are some potential pitfalls of using a foreach loop in PHP to display content from an array?
- What is the correct way to handle quotation marks in PHP if statements when using them in SQL queries?
- In what scenarios would encrypting passwords using functions like MD5 be sufficient for securing PHP applications?