How can CSS be applied to tables generated using PHP echo statements?
When generating tables using PHP echo statements, CSS can be applied by adding inline styles directly to the HTML elements within the echo statements. This allows for styling of individual table elements such as rows, columns, or cells. Alternatively, you can also define a CSS class and apply it to the table elements within the PHP echo statements.
<?php
echo "<table style='border: 1px solid black;'>";
echo "<tr>";
echo "<th style='background-color: #f2f2f2; padding: 5px;'>Header 1</th>";
echo "<th style='background-color: #f2f2f2; padding: 5px;'>Header 2</th>";
echo "</tr>";
echo "<tr>";
echo "<td style='padding: 5px;'>Data 1</td>";
echo "<td style='padding: 5px;'>Data 2</td>";
echo "</tr>";
echo "</table>";
?>
Keywords
Related Questions
- What are some best practices for handling user input validation and correction before storing data in a database using PHP?
- What are some potential pitfalls of dynamically setting parameters in a PHP class constructor?
- How can the encoding method, such as quoted-printable, affect the content of emails sent via PHP?