【问题标题】:echo background-image回声背景图像
【发布时间】:2012-10-25 11:56:35
【问题描述】:

我正在尝试在 .phtml 中回显背景图像以发送电子邮件。

但是我在引用时遇到了麻烦。图片未显示。

<?php echo '
    Plataforma <a href="http://xxxx.com/">http://xxxx.com/</a>
    <br>
    <div style="width:220px; height:30px; background-color:black; background-repeat: no-repeat; background-image:url("http://www.inova-ria.pt/images/UebeImg/Thumb/Img_153_363_T.jpg")"></div>
'
?>

IDE 验证此代码是否正确,但图像未显示在发送的电子邮件中。

【问题讨论】:

  • 一些主要的电子邮件客户端不支持背景图像,请记住这一点。包括展望 07,10 和 13

标签: php echo


【解决方案1】:
<?php echo '
    Plataforma <a $href="http://xxxx.com/">http://xxxx.com/</a>
    <br>
    <div $style="width:220px; height:30px; background-color:black; background-repeat: no-repeat; background-image:url(\"http://www.inova-ria.pt/images/UebeImg/Thumb/Img_153_363_T.jpg\")"></div>
    '
?>

style属性的值用双引号括起来,所以里面的双引号必须转义。

【讨论】:

    【解决方案2】:

    你需要改变这个:

    background-image:url("http://www.inova-ria.pt/images/UebeImg/Thumb/Img_153_363_T.jpg")
    

    到:

    background-image:url('http://www.inova-ria.pt/images/UebeImg/Thumb/Img_153_363_T.jpg')
    

    双引号在错误的地方切断了你的 DOM,导致它被误读。

    【讨论】:

      【解决方案3】:

      您的 CSS 无效。更改此行:

      background-image:url("http://www.inova-ria.pt/images/UebeImg/Thumb/Img_153_363_T.jpg")
      

      这样读:

      background-image:url('http://www.inova-ria.pt/images/UebeImg/Thumb/Img_153_363_T.jpg')
      

      因为它位于 style="" 属性中,所以 background-image 行中的 " 符号表示样式属性的结束,而不是图像的路径。

      【讨论】:

        【解决方案4】:

        尝试使用单引号,例如在图片的 URL 中:

        <?php echo '
            Plataforma <a href="http://xxxx.com/">http://xxxx.com/</a>
            <br>
            <div style="width:220px; height:30px; background-color:black; background-repeat: no-repeat; background-image:url(\'http://www.inova-ria.pt/images/UebeImg/Thumb/Img_153_363_T.jpg\')"></div>
        '
        ?>
        

        【讨论】:

          【解决方案5】:

          其他答案均未解决此问题(gmail、hotmail)。这将起作用

          <?php echo '
              Plataforma <a href="http://xxxx.com/">http://xxxx.com/</a>
              <br>
              <div style="width:220px; height:30px; background-color:black;">
                  <img src="http://www.inova-ria.pt/images/UebeImg/Thumb/Img_153_363_T.jpg">
              </div>
              '; ?>
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2022-07-21
            • 1970-01-01
            • 1970-01-01
            • 2022-06-12
            • 1970-01-01
            • 2012-07-03
            • 2022-01-26
            相关资源
            最近更新 更多