真的有必要引用 url() 的值吗? [英] Is quoting the value of url() really necessary?

查看:33
本文介绍了真的有必要引用 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 规定什么是正确的方式?

推荐答案

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(' 后跟可选的空格,后跟可选的单引号 (') 或双引号 (") 字符,后跟 URI 本身,后跟可选的单引号 (')或双引号 (") 字符后跟可选的空格,后跟 ')'.两个引号字符必须相同.

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

这篇关于真的有必要引用 url() 的值吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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