dsiy62758 2017-04-20 17:16
浏览 131
已采纳

如何在PHP echo中添加背景attr?

I'm trying to include a background image to .win_box as an attr. But because I'm using PHP to echo, the quotes are conflicting.

I don't want to use <style> because each .win_box may have a different image and I don't want to assign a separate id for each (dynamic).

<?php 
echo "<div class='col-xs-5 col-sm-3 col-md-3 col-lg-2' id='title'> <a href='#' class='win_link'> <div class='win_box' style='background: url("https://i.ytimg.com/vi/8sME-VxUQQA/hqdefault.jpg?custom=true&w=196&h=110&stc=true&jpg444=true&jpgq=90&sp=68&sigh=EgyGW3D0KWyu5ei-2aUz8FPI_Jc");'> <i class="fa fa-play" aria-hidden="true" id='video'></i>

   <div class='description'> Earn 5 Points </div>

   </div> </a>
  </div>";
?>
  • 写回答

1条回答 默认 最新

  • dpps0715 2017-04-20 17:22
    关注

    You will have to either escape the quotes, or use echo with single quotes (which will let you use double quotes normally. For example:

    <?php 
    echo '
    <a href="#" class="win_link"> 
      <div class="win_box" style="background: url(\'https://i.ytimg.com/vi/8sME-VxUQQA/hqdefault.jpg?custom=true&w=196&h=110&stc=true&jpg444=true&jpgq=90&sp=68&sigh=EgyGW3D0KWyu5ei-2aUz8FPI_Jc\');"> 
        <i class="fa fa-play" aria-hidden="true" id="video"></i>
        <div class="description"> Earn 5 Points </div>
      </div>
    </a>';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

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

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

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

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

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

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

客服 返回
顶部