I am adding a line through t <table> with foreach .
At some point, I want the cell to have a gray background based on the percentage calculated in PHP.
Example: 50% means half the background of the cell with gray, the rest will remain empty | 33.33% = 1/3 of the background, etc.
The problems I ran into is either the text in the <td> received by any other div, if I applied the color to the <td> , I also override the text later, etc.
Here is the code:
$percent = 1/3; // For example $percent_friendly = number_format( $percent * 100, 2 ); //This will return 33.33 echo '<td>'.$percent_friendly.' % <div style="background-color: grey"> // So I want the grey to fill 33.33% of the space </div> <div style="background-color: white"> </div> </td>';
and applied style:
table { margin-left:auto; margin-right:auto; font-size:18px; } table, th, td { text-align: center; border: 1px solid black; position:relative; }
I need to miss something, but CSS is really not my thing, thanks for the help or help.
source share