doujiexi1824 2016-01-21 17:30
浏览 91
已采纳

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

I have an index.php which I have successfully filled with content from the relevant tables in a mysql database. However there is one section (events) that has a background image that is defined in the css. However after changing the css to a php and making sure to give mention <?php header("Content-type: text/css; charset: UTF-8"); ?>, background-image:url:"<?php echo $eventsrow[0]['filepath'];?>" was throwing the style of the entire document out of whack apart from not showing the image.

So i decided to put the image call in the index.php instead, as I had done for the other sections, by using inline style: <div class="monthevent" style="background-image:url("<?php echo $eventsrow[0]['filepath'];?>");">

However the image does not appear at all. Is there something wrong with this? Would appreciate any light. A var_dump on the above variable, gives the correct value: ie. the filepath, but the image is not displayed; also I tried adjusting the path relative to the css (just in case), but no image turned up. Would appreciate any thoughts on what the issue might be?

  • 写回答

1条回答 默认 最新

  • dtqjbbr5283 2016-01-21 17:32
    关注

    You have to use like this:

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

    Not the double quotes inside the url, use single quotes to differentiate the url!

    If you use double quotes:

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

    If you use single quotes:

    <div class="monthevent" style="background-image:url('your_url.com');">
    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Matlab问题解答有两个问题
  • ¥50 Oracle Kubernetes服务器集群主节点无法访问,工作节点可以访问
  • ¥15 LCD12864中文显示
  • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决
  • ¥15 gsoap生成onvif框架
  • ¥15 有关sql server business intellige安装,包括SSDT、SSMS。
  • ¥15 stm32的can接口不能收发数据
  • ¥15 目标检测算法移植到arm开发板
  • ¥15 利用JD51设计温度报警系统
  • ¥15 快手联盟怎么快速的跑出建立模型