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 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?