1

Images are displayed underneath description of the problem; labeled respectively. Code is displayed at the end of the post.

The code displays correctly as shown in chrome (image 1), but incorrectly in firefox, internet explorer (referred to as I.E. later in post) and safari (image 2). When the table heading contents are removed, the table widths display correctly (image 3). I know the table widths are being calculated correctly as the <td>...</td> part of the table is consistently correct across all three browsers. The issue is purely in the display, does anyone have any ideas on how to fix this?

As the table should be displayed in Chrome:

http://imgur.com/a/FlwYX

The table in IE/Firefox/Safari:

http://imgur.com/a/FlwYX

The table in IE/Firefox/Safari when the <th>... </th> contents are emptied (no other code changes):

http://imgur.com/a/FlwYX

Code for table headings:

echo "<table class='main' style='width: 100%;' cellpadding='0' cellspacing='0'><tr>";
echo "<th style='width: 20%;'>Student Name</th>";
while($row2 = mysql_fetch_array($result2))
{
    extract($row2);
    echo "<th style='width: calc(80% / ".$numclasses.");'>**".$classname."**</th>";
}
echo "<th style='width: calc(80% / ".$numclasses.");'>**No Class**</th>";
...<insert correctly behaving <td>...</td> here...
echo "</table>";
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Justice
  • 169
  • 1
  • 2
  • 9

1 Answers1

0

the calc css property works on latest version of browsers.You can use vender prefixes for for some older ones. The best thing to do is calculate the calculation in php and then output the result using echo.check this in can i use calc()

Haben
  • 95
  • 5
  • How would I go about using php to calculate a width? using a percentage of a percentage? (sorry if it seems like a stupid question to you...) Thank you for letting me know the reason that it wasn't working was due to CSS though! – Justice Aug 18 '13 at 23:45
  • you could get the elements width in javascript or jquery and divide it but since you are outputting it dynamically i don't think that is possible – Haben Aug 18 '13 at 23:53
  • is it possible to get however many columns I require in PHP and then run the javascript afterwards by any chance? (I have never used javascript - let alone with PHP... I'd be completely lost starting it in this way...) – Justice Aug 22 '13 at 03:12
  • [check this stackoverflow question](http://stackoverflow.com/questions/5310216/passing-php-variable-into-javascript) you can output your php variable inside a script tag as a javascript variable value – Haben Aug 22 '13 at 16:52
  • Thank you very much for your time! I'm currently looking into doing this and it appears to be starting to work! – Justice Aug 24 '13 at 19:19