dslijian2015 2014-09-28 00:20
浏览 127
已采纳

如何将PHP添加到CSS?

I was wondering if anyone can help. I am trying to add PHP code, which is retrieving an image from a database, into CSS.

I have the small section of CSS code on my example.php page and need to have different images for backgrounds depending on what variables were posted to the example.php page.

The terrible code that I have come up with is as follows

    <style>
    .par-surround {
        background-repeat: no-repeat;
        background-image:<?php <img src=<?=$subject['picture']?>border="0" width="740px"         height="auto"/> ?>  ; 
        background-position: center top;
     }
     </style>

I don't know if this can be done or if I have to do it a completely other way. Any help would be appreciated, thank you.

  • 写回答

2条回答 默认 最新

  • dongpu8935 2014-09-28 01:05
    关注

    The reasodin is correct. You just ned to have a valid PHP code:

    <style>
        .par-surround {
            background-repeat: no-repeat;
            background-image: url(<?php echo $subject['picture'] ?>); 
            background-position: center top;
         }
     </style>
    

    Also make sure $subject is defined and has a value, BEFORE you output the CSS code.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误
  • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
  • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
  • ¥100 描述一下元器件的基本功能,pcba板的基本原理
  • ¥15 STM32无法向设备写入固件
  • ¥15 使用ESP8266连接阿里云出现问题
  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果