我想以5x2的方格显示10个图像实例。我用PHP / HTML / CSS编写了这个代码:
for ($i = 0; $i <= 9; $i++) {
if ($i >= 5) {
$top_position=780;
echo "1". "<br />";
}else {
$top_position = 430;
echo "2". "<br />";
}
if ($i >= 5) {
$u = 20 + 250 * $i - 250 * 5;
}
else {
$u = 20 + 250 * $i;
}
echo "<style> " . ".background" . $u . "{" . "position: absolute;
left: " . $u . "px;" . "top: " . $top_position . "px;" . "</style>";
echo "<img src=http://localhost/Summoner's%20Index/images/scheme.png class=background" . $u . ">";}
我在第二行得到一个5x1,并且正如我得到的文字:1111122222,所以好像程序可以正常工作。为什么我只获得5images而不是10?
答案 0 :(得分:0)
查看以下代码:
for ($i = 1; $i <= 10; $i++) {
echo "<img src=http://localhost/Summoner's%20Index/images/scheme.png class=background" . $u . ">";
if ($i == 5){
echo "<br>";
}
}