【问题标题】:bootstrap image row out of place引导图像行不合适
【发布时间】:2016-06-24 06:03:42
【问题描述】:

[已解决]

我已经使用占位符编写了 4 张 500x300 图像的水平行,这非常好,但是当我尝试用相同尺寸的文件夹(使用 php)中的图像替换这些图像时,前 2 个图像包含被淘汰了,而最后两个是它们所属的地方。我附上了截图,下面的代码是我用来获取图像行的代码。

<div class="row" style="margin-top:1px">
<?php
$directory = 'images';
if (! is_dir($directory)) {
exit('Invalid diretory path');
}
$files = array();
foreach (scandir($directory) as $file) {
?>

<div class="col-sm-3 col-xs-6" >
<a href="#" >
<img  class="img-responsive portfolio-item" src="<?php echo "images/$file"; ?>" alt="">
</a>
</div>

<?php
}
?>

</div>

this is what i get in the browser

【问题讨论】:

  • 我对 PHP 了解不多,但似乎你应该拥有这个 &lt;img class="img-responsive portfolio-item" src="&lt;?php echo 'images/$file'; ?&gt;" alt=""&gt;
  • 不,使用 ' 而不是 " 会阻止您访问字符串中的变量。

标签: php css twitter-bootstrap-3


【解决方案1】:

使用 glob 而不是数组解决了这个问题。 PHP 包括 .和目录结构的双点,因此创建了 2 个空图像。

【讨论】:

    猜你喜欢
    • 2018-10-13
    • 2016-06-15
    • 2022-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-13
    • 2017-04-03
    • 1970-01-01
    相关资源
    最近更新 更多