doujiong2533 2018-09-15 09: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 09:49
    关注

    Please concate your color variable with . Delimiter

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部