索引中的内联样式.php不显示从数据库拉取的背景图像


Inline style in index.php does not display background image pulled from database

>我有一个索引.php我已经成功地填充了mysql数据库中相关表中的内容。但是,有一个部分(事件)具有在 css 中定义的背景图像。然而,在将 css 更改为 php 并确保提及<?php header("Content-type: text/css; charset: UTF-8"); ?>之后,除了不显示图像之外,background-image:url:"<?php echo $eventsrow[0]['filepath'];?>"整个文档的风格都失常了。

因此.php我决定将图像调用放在索引中就像我对其他部分所做的那样,使用内联样式:<div class="monthevent" style="background-image:url("<?php echo $eventsrow[0]['filepath'];?>");">

但是,图像根本不显示。这有什么问题吗?将不胜感激任何光线。对上述变量的var_dump给出正确的值:即。文件路径,但不显示图像;我也尝试调整相对于 css 的路径(以防万一),但没有出现图像。希望对问题可能是什么有任何想法?

你必须像这样使用:

<div class="monthevent" style="background-image:url('<?php echo $eventsrow[0]['filepath'];?>');">

网址内不要用双引号,用单引号来区分网址!

如果使用双引号:

<div class="monthevent" style="background-image:url("your_url.com");">
</div>

如果使用单引号:

<div class="monthevent" style="background-image:url('your_url.com');">
</div>