我应该在我的样式表中使用以下哪些?
/* Example #1: */ background-image: url(image.png);
/* Example #2: */ background-image: url("image.png");
/* Example #3: */ background-image: url('image.png');
W3C 将什么指定为正确的方式?
最佳答案
W3C 说引号是可选的,您的所有三种方式都是合法的。
开始和结束报价只需要是相同的字符。
如果您的 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.
转义特殊字符:
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: '\(', '\)'.
关于css - 真的有必要引用 url() 的值吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2168855/