引用url()的值真的有必要吗?

问题描述:

我应该在我的样式表中使用以下哪一个?

Which of the following should I use in my stylesheets?

/* Example #1: */ background-image: url(image.png);
/* Example #2: */ background-image: url("image.png");
/* Example #3: */ background-image: url('image.png');

W3C以何种方式指定

What does the W3C specify as the correct way?

W3C说引号是可选的,所有三种方式都是合法的。

The W3C says quotes are optional, all three of your ways are legal.

开始和结束报价只需要是相同的字符。

Opening and closing quote just need to be the same character.

如果您的网址中有特殊字符,您应该使用引号或转义字符(见下文)。

If you have special characters in your URL, you should use quotes or escape the characters (see below).

语法和基本数据类型


URI值的格式为'url(',后跟可选的单引号(')或双引号()字符,后跟可选的单引号(')或双引号()字符后跟可选的空格,后跟')'。两个引号字符必须相同。

The format of a URI value is 'url(' followed by optional white space followed by an optional single quote (') or double quote (") character followed by the URI itself, followed by an optional single quote (') or double quote (") character followed by optional white space followed by ')'. The two quote characters must be the same.

转义特殊字符:


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

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: '\(', '\)'.