我有一个包含5列的表,用于在每列中存储图像。图像宽度相对于td为100%,图像高度与其宽度成比例。我存储了大约25张相同图像的图片,我使用该表在5列中显示这些图片。问题是第一列高度的图片总是比高度略高其他四列中的图片,即使它们是同一图像。请看下面的代码:
<style>
img {
width: 100%;
}
table,td {
border: 1px solid black;
}
</style>
<?php
include('all.php'); //includes all the necessary functions;
$picture = gd("image/images"); //get image reference link from database and store in multi-dimensional array;
$count = count($picture); //return number of reference links
echo "<table>";
while ($count > 0) {
$tempCount = 0;
echo "<tr>";
while ($tempCount < 5) {
if ($count > 0) {
$count--;
$temp = $picture[$count][0];
echo "<td><img src = 'uploads/$temp'></td>";
}
$tempCount++;
}
echo "</tr>";
}
echo "</table>";
?>
答案 0 :(得分:0)
通过将td的宽度设置为20%来修复它。
<style>
img {
width: 100%;
}
table,td {
border: 1px solid black;
}
td {
width: 20%;
}
</style>