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

标签 css w3c

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

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

W3C 将什么指定为正确的方式

最佳答案

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

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

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

Syntax and basic data types

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/

相关文章:

java - 如何使用java7的org.w3c.dom.html包而不是Jsoup来解析HTMLDocument?

添加/删除字段的 Javascript 函数

parsing - 如何使用 W3C EBNF-Notation 并生成解析器生成器?

jquery - 工具提示未在 Internet Explorer 中正确显示

CSS:删除通用选择器应用的边框

css - 自定义 CSS 边框样式(这个很棘手!)

javascript - 基于浏览器窗口大小的条件 javascript 执行?

css - JavaFX2 : can I set opacity for Nodes' content and stroke separately?

javascript - 如何检查监听器事件是否为被动事件?

css - 在CSS Flexbox中,为什么没有“justify-items”和“justify-self”属性?