简体   繁体   English

一些图片在`background-image:url()` 中不起作用

[英]Some images not working in `background-image:url()`

Some images not working in background-image:url() , i cant figure out that does i need to remove ( and ) from image name or anything else is an issue?有些图像在background-image:url()中不起作用,我不知道我是否需要从图像名称中删除( and )或其他任何问题?

any help will be appreciated.任何帮助将不胜感激。

here is an working and not working examples.这是一个工作和不工作的例子。

 <!-- Not Working --> <div style="background-image:url(https://ignite.galify.com/images/tx9gyzjfb24712-(1).jpg)"> img </div> <!-- Working --> <div style="background-image:url(https://ignite.galify.com/images/9mspqz9gqb1561725209327568845756.jpg)"> img1 </div>

Escape special characters ( \\ in front of ( and ) ) in the URL. 特殊字符转义( \\前面() )在URL中。

 <!-- Use CSS escape character to escape special characters --> <div style="background-image:url(https://ignite.galify.com/images/tx9gyzjfb24712-\\(1\\).jpg)"> img </div> <!-- Working --> <div style="background-image:url(https://ignite.galify.com/images/9mspqz9gqb1561725209327568845756.jpg)"> img1 </div> 

Alternatively, use single quote ( ' ) to enclose the image URL: 或者,使用单引号( ' )将图像URL括起来:

 <!-- Use single quote (') to enclose image URL --> <div style="background-image:url('https://ignite.galify.com/images/tx9gyzjfb24712-(1).jpg')"> img </div> <!-- Working--> <div style="background-image:url(https://ignite.galify.com/images/9mspqz9gqb1561725209327568845756.jpg)"> img1 </div> 

Just add single quotation marks around the url. 只需在网址周围添加单引号即可。 If you have special characters in your URL, you should use quotes or escape the characters. 如果URL中包含特殊字符,则应使用引号或转义字符。 Give this a read for further information. 这个以获取更多信息的读取。

 Now Working <div style="background-image:url('https://ignite.galify.com/images/tx9gyzjfb24712-(1).jpg')"> img </div> Working <div style="background-image:url(https://ignite.galify.com/images/9mspqz9gqb1561725209327568845756.jpg)"> img1 </div> 

尝试在url添加单引号:

<div style="background-image:url('https://ignite.galify.com/images/tx9gyzjfb24712-(1).jpg')"> img </div>

In my case I had an issue with some urls containing a single quote.就我而言,我遇到了一些包含单引号的网址的问题。 Fixed it surrounding the url with &quot;&quot;修复了它围绕 url :

<div style="background-image: url(&quot; ${url} &quot;);"></div>

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

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