简体   繁体   中英

PHP - How to change font size of HTML table?

I'm generating table in a foreach loop

echo "<tr>";

    echo "<td align='left' bgcolor='$bgclr'>".$monthName."</td>";   
    echo "<td align='center' bgcolor='$bgclr'>".$id."</td>";    
    echo "<td align='center' bgcolor='$bgclr'>".$total."</td>"  

echo "</tr>";

I need to increase font size of the table, but i'm not sure how. Does the html table has attribute to set font size or I should use CSS ?

Just use font style css in style attribute :

echo "<tr>";

    echo "<td align='left' bgcolor='$bgclr' style='font-size:10px'>".$monthName."</td>";   
    echo "<td align='center' bgcolor='$bgclr' style='font-size:10px'>".$id."</td>";    
    echo "<td align='center' bgcolor='$bgclr' style='font-size:10px'>".$total."</td>"  

echo "</tr>";

use the html styling on the echoed elements. For example echo '<table style="font-size: 100px">';

You need to define font size in one variable and then use in inline as below code:

foreach{
    $fontsize = 'font-size: '.((isset(FONT_SIZE_IN_FOREACH))?FONT_SIZE_IN_FOREACH:12);
echo "<tr>";

    echo "<td align='left' bgcolor='$bgclr' style='$fontsize'>".$monthName."</td>";   
    echo "<td align='center' bgcolor='$bgclr'>".$id."</td>";    
    echo "<td align='center' bgcolor='$bgclr'>".$total."</td>"  

echo "</tr>";
}

You can add class to the table and write css for that class.

HTML:

<table class='fontsize'>

</table>

CSS:

.fontsize {
   font-size:16px;
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM