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

查看:115
本文介绍了引用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: '\(', '\)'.

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

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