我刚注意到这个奇怪的事情。所以我有一个CSS主文档,我用一个PHP变量覆盖了其中的一个部分,我在index.php的开头添加了一个PHP变量,以根据服务器上的文件夹中的内容动态更改背景图像。用PHP替代CSS并不显示相同的结果
在典型的CSS我有这样的:
.fullscreen{
background: url('./Hero_Image/image01.jpg') no-repeat center center;
}
而且我有作为调整窗口的大小被适当缩放的浏览器窗口,尺度.fullscreen类部分一个不错的,全屏幕图像背景。
但是,当我试图让这个充满活力的,使用PHP和压倒一切的像这样:
<?php
include '_SiteResources/php/loadHeroImage.php'; //<< note: output is basically an echo of the URL of the first file in a folder
?>
<head>
<style type="text/css">
.fullscreen{ background: url('<?php getHeroImage(); ?>') no-repeat center center;}
</style>
</head>
我注意到使用PHP没有显示同样的结果覆盖。是的,它也是全屏,但我注意到它也不像窗口缩放那样缩放,就像原来的CSS实现一样;它似乎显示扩大了,并没有与浏览器窗口扩展。
这是为什么?
这里的每个请求loadHeroImage.php代码:
<?php
function getHeroImage(){
$h = opendir('./Hero_Image/'); //Open the current directory
while (false !== ($heroImage = readdir($h))) {
if($heroImage != '.' && $heroImage != '..') { //Skips over . and ..
$heroFileInfo = pathinfo($heroImage);
$heroImagePath = $heroFileInfo['dirname'];
$heroImageBase = $heroFileInfo['basename'];
// $heroImageFullPath = $heroImagePath.$heroImageBase;
echo './Hero_Image/'.$heroImageBase.' ';
break;
}
}
}
?>
什么是PHP实现的(HTML)输出?它与静态CSS实现有什么不同? –
发布代码loadHeroImage.php –
也,如果你有错误报告你会注意到,这是抛出一个错误,应该在它后面的缺少分号..'getHeroImage()' –