简体   繁体   English

无法将 img 与背景图像一起使用:url()

[英]Unable to use img with background-image: url()

I am having trouble to display my image in background of my html.我无法在 html 的背景中显示我的图像。

 <div class="item active" style="background-image:URL("/img/abc-1.jpg");"></div>

Why the url cant display my img instead, in the inspection I have done in google chrome, it shows out:为什么url不能显示我的img,在我在谷歌浏览器中完成的检查中,它显示:

<div class="item active" style="background-image:URL(img abc-1.jpg);"></div>

Thanks谢谢

I think you made a mistakes.我认为你犯了一个错误。 I think you are referring to w3schools .我认为您指的是w3schools

The correct way to do it is: <div class="item active" style="background-image:URL('/img/abc-1.jpg');"></div>正确的做法是: <div class="item active" style="background-image:URL('/img/abc-1.jpg');"></div>

without the double quotation mark没有双引号

将双引号改为单引号:

<div class="item active" style="background-image:URL('/img/abc-1.jpg');"></div>

You Need to use single quotes '' like this: style="background-image:url('/img/abc-1.jpg')您需要像这样使用单引号 '': style="background-image:url('/img/abc-1.jpg')

This way you escape the "" double quotes used on the style property.这样你就可以转义 style 属性上使用的 "" 双引号。

If you need the double quotes, use escape sequence.如果需要双引号,请使用转义序列。 This won't close the style attribute.这不会关闭样式属性。

<div class="item active" style="background-image:URL(\"img abc-1.jpg\");"></div>

Background Url should be written within single Quotes, you have used double quotes because of which style tag technically closes at style="background-image:URL("背景 URL 应该写在单引号内,您使用了双引号,因为技术上将样式标记关闭在style="background-image:URL("

Try using single quotes style="background-image:URL('/img/abc-1.jpg');"尝试使用单引号style="background-image:URL('/img/abc-1.jpg');"

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

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