简体   繁体   English

在内联css背景图像中回显php在url中删除'/'

[英]echo php in an inline css background-image deletes '/' in url

Ive read through some of the other topics but i couldnt find a solution that worked. 我已经阅读了一些其他主题,但我找不到有效的解决方案。 But someway the the url shows up as http:="" mysite.com="" wp-content="" uploads="" 2015="" 08="" matchups-1.png" ) 但是,某些网址显示为http:="" mysite.com="" wp-content="" uploads="" 2015="" 08="" matchups-1.png"

This is the code I'm using. 这是我正在使用的代码。 How do I prevent it from adding the extra "" and spaces? 如何防止它添加额外的""和空格?

<div style="background-image: url("<?php echo $bgimage; ?>"); background-position:cover;"></div>

I've tried to code like this, but this didnt work: 我试过像这样的代码,但这不起作用:

<div style="background-image: url(\'<?php echo $bgimage; ?>\'); background-position:cover;"></div>

as some answers suggested but still I'm either doing something wrong or it doesn't work. 正如一些答案所暗示的那样但我仍然做错了什么或者它不起作用。 Can anyone tell me a solution? 谁能告诉我一个解决方案? thanks. 谢谢。

You can simply use 你可以简单地使用

<div style="background-image: url('<?php echo $bgimage; ?>'); background-position:cover;"></div>

or 要么

<div style="background-image: url(<?php echo $bgimage; ?>); background-position:cover;"></div>

quotes are not necessary in an url 网址中不需要引号

问题是双引号"你用于url()字符。只是尝试没有或用单引号代替。

<div style="background-image: url(<?php echo $bgimage; ?>); background-position:cover;"></div>

you should solve it with 3 ways.. 你应该用3种方法解决它..

  1. put this in the 把它放进去

 <style type="text/css"> .logo { background: url(<?php echo $img_url; ?>); } </style> 

  1. Or you can simply use the inline style attribute and define the background-image. 或者您可以简单地使用内联样式属性并定义背景图像。

     <div style="background-image: url(<?php echo $img_url; ?>);"> 

  2. or With the use of JQuery 或者使用JQuery

 <input type="text" class="imgcntnt" /> <script type="text/javascript"> var input_image = $('input.imgcntnt').val(); $('body').css('background', 'url(' + input_image + ')'); </script> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM