简体   繁体   中英

Applying css to a php table

I have a generated php table which I would like to apply style in my style sheet, so for example top:15px, left:10px ect..., not sure how call the table and link it with css -

echo "<table border=1>";
for ($i=0;$i<count($calls);$i++){
  for ($j=0;$j<count($days);$j++){
    $k = $days[$i].$times[$j];
    if (array_key_exists($k,$date)){
      echo "<td colspan='{$date[$k][1]}'>".
           "{$date[$k][0]}</td>";
      $j+=$date[$k][1]-1;
    }else
      echo "<td style='color:gray'>$k</td>";
  }

  echo "</tr>";
}
echo "</table>";

any help much appreciated, thank you

echo '<table style="top: 15px; left:10px;">';

or

echo '<table class="someClass">';

and then use CSS

.someClass{
top: 15px;
left: 10px;
}

Give the table an id

echo "<table id=\"my_table\" border=1>";

And then use this in the <head> tag of the document:

<style type="text/css">

  #my_table {
    top: 15px;
    ...
  }

</style>
echo "<table style=\"border: 1px; top:15px; left: 10px;\">";

这句话行不通吗?

echo "<table border=1 style=\"top:15px; left:10px\">";

for ($i=0; $i<count($calls); $i++) {
    for ($j=0;$j<count($days);$j++) {
        $k = $days[$i].$times[$j];

        if (array_key_exists($k,$date)) {
            echo "<td colspan='{$date[$k][1]}'>".
                 "{$date[$k][0]}</td>";
            $j+=$date[$k][1]-1;
        } else {
            echo "<td style='color:gray'>$k</td>";
        }
    }

    echo "</tr>";
}

echo "</table>";

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