What are some best practices for designing tables for mobile devices using CSS in PHP?
When designing tables for mobile devices using CSS in PHP, it is important to ensure that the tables are responsive and optimized for smaller screen sizes. This can be achieved by using media queries to adjust the table layout based on the device width. Additionally, it is recommended to use percentage-based widths for columns and to avoid fixed widths that may not display properly on mobile devices.
<table class="responsive-table">
<tr>
<th>Header 1</th>
<th>Header 2</th>
<th>Header 3</th>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
</tr>
</table>
<style>
.responsive-table {
width: 100%;
}
@media only screen and (max-width: 600px) {
.responsive-table th, .responsive-table td {
display: block;
width: 100%;
}
}
</style>