CSS background-image - 什么是正确的用法? [英] CSS background-image - What is the correct usage?

查看:171
本文介绍了CSS background-image - 什么是正确的用法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CSS background-image属性的正确用法是什么?
我想要了解的关键是


  1. 是否需要在引号中: background-image:url('images / slides / background.jpg');

  2. 它可以是一个相对路径完整网址?

  3. 我应该注意的任何其他问题,以确保其在符合标准的浏览器中正常工作。


< div路径可以是完整的或相对的(当然,如果图像来自另一个域,它必须是完整的)。



您不需要在URI中使用引号;语法可以是:

  background-image:url(image.jpg); 

  background-image:url(image.jpg); 

但是,从 W3


诸如括号,空格字符,单引号(')和双引号()的非引号URI必须用反斜杠转义,以使生成的URI值是URI令牌:'\(','\ )'。


因此,在这样的实例中,需要使用引号或双引号或转义字符。 p>

What is the correct usage of the CSS background-image property? The key things I am trying to understand is

  1. Does it need to be in quotes i.e.: background-image: url('images/slides/background.jpg');
  2. Can it be a relative path (as above) or must it be a full URL?
  3. Any other points I should be aware of to make sure it works correctly across standards compliant browsers.

解决方案

The path can either be full or relative (of course if the image is from another domain it must be full).

You don't need to use quotes in the URI; the syntax can either be:

background-image: url(image.jpg);

Or

background-image: url("image.jpg");

However, from W3:

Some characters appearing in an unquoted URI, such as parentheses, white space characters, single quotes (') and double quotes ("), must be escaped with a backslash so that the resulting URI value is a URI token: '\(', '\)'.

So in instances such as these it is either necessary to use quotes or double quotes, or escape the characters.

这篇关于CSS background-image - 什么是正确的用法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆