Is quoting the value of url() really necessary?

后端 未结 7 1961
情话喂你
情话喂你 2020-11-22 09:40

Which of the following should I use in my stylesheets?

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


        
7条回答
  •  不思量自难忘°
    2020-11-22 10:26

    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).

    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.

    Escaping special characters:

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

提交回复
热议问题