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
- Are there any specific considerations to keep in mind when using LIKE in a MySQL query in PHP?
- How can PHP be used to handle database constraints and prevent errors like duplicate entries?
- How can one ensure that a generated account is not available to other members on a PHP account generator website?