doujiong2533 2018-09-15 17:42
浏览 292
已采纳

在PHP语句中编辑html <div>

I'm coding a PHP script supposed to create some boxes inside a webpage. I'm having problems setting the background color of the box. Here is the part of code involved:

 <div class="container">
 //$color is declared at the top of my file
   <?php
    echo '<div style="background-color: '<?='$color'?>'; width: 30px; height: 30px">'
    ?>

</div>

So background-color should take the color from the $color variable, but i don't know how to make that PHP part inside the html statement. The error i get is syntax error, unexpected '?'

  • 写回答

4条回答 默认 最新

  • dt97868 2018-09-15 17:49
    关注

    Please concate your color variable with . Delimiter

    <?php
      echo '<div style="background-color: '.$color.'; width: 30px; height: 30px">'
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置