CSS 背景:外部服务器上的 url()

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12194227/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 20:02:37  来源:igfitidea点击:

CSS background:url() on external server

cssbackground-imageexternal

提问by Champ

I am using the following css rule:

我正在使用以下 css 规则:

background: url("http://example.com/background.jpg");

It is not working and I suppose it is because referring to external servers is not supported. Is this true? If so, what kind of workaround I might use?

它不起作用,我想这是因为不支持引用外部服务器。这是真的?如果是这样,我可以使用什么样的解决方法?

Not sure if it's relevant, but I need this inline. Testing right now on JSFiddle.

不确定它是否相关,但我需要这个内联。现在在 JSFiddle 上测试。

回答by Champ

There may be 2 reasons why your background is not working

您的背景不起作用可能有两个原因

  1. Your container doesn't have height, width or padding (no area to show the background)
  2. The URL you specified is broken or incorrect. There is no image at the URL you specified.
  1. 您的容器没有高度、宽度或内边距(没有显示背景的区域)
  2. 您指定的 URL 已损坏或不正确。您指定的 URL 中没有图像。

Otherwise, your background: url("http://example.com/background.jpg");is Correct

否则,你background: url("http://example.com/background.jpg");正确的

回答by Colin Granger

I'm not sure if this was resolved or not but I had a similar problem and I found a simple solution. First off, I used background-image instead of background. Second, I made sure to include the full url. So instead of background: url("http://example.com/background.jpg"); I would put background-image: url("http://www.example.com/background.jpg");

我不确定这是否已解决,但我遇到了类似的问题,我找到了一个简单的解决方案。首先,我使用背景图像而不是背景。其次,我确保包含完整的 url。所以,而不是背景: url(" http://example.com/background.jpg"); 我会把 background-image: url(" http://www.example.com/background.jpg");

回答by Jezen Thomas

It does work. There must be something wrong with your URL.

它确实有效。您的网址一定有问题。

http://jsfiddle.net/ebLQQ/

http://jsfiddle.net/ebLQQ/