【发布时间】:2015-09-23 01:15:02
【问题描述】:
我有这段代码,我用它来显示随机图像。但图片显示在网站的左上角。我希望能够根据需要定位图像。我必须对上述代码顺序进行哪些更改。 这是代码——
/*
* Name your images 1.jpg, 2.jpg etc.
*
* Add this line to your page where you want the images to * appear: <?php include"randomimage.php"; ?>
*/
// Change this to the total number of images in the folder
$total = "2";
// Change to the type of files to use eg. .jpg or .gif
$file_type = ".jpg";
// Change to the location of the folder containing the images
$image_folder = "sample.url.com";
// You do not need to edit below this line
$start = "1";
$random = mt_rand($start, $total);
$image_name = $random . $file_type;
echo "<img src=\"$image_folder/$image_name\" alt=\"$image_name\ />";
?>
提前致谢
【问题讨论】:
-
使用 CSS 将图像定位到您想要的位置。
-
这很正常。图像出现在那里,它们具有出现的样式。如果您不提供样式,则将采用浏览器的默认样式。顺便说一句,它独立于 PHP,更多的是 HTML 和 CSS 的工作方式。