我们应该在 css 背景 url (“....”) 中使用哪种类型的引号?需要单引号、双引号还是不需要引号?

发布于 2024-08-17 04:28:16 字数 199 浏览 2 评论 0原文

这个

background:url(http://url);

这个

background:url("http://url");

或者这个

background:url('http://url');

this

background:url(http://url);

this

background:url("http://url");

or this

background:url('http://url');

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

那片花海 2024-08-24 04:28:16

根据 CSS 规范<,所有三个示例的 URL 位都是有效的 CSS /a>.

请注意,规范标识了 URL 中的某些字符,如果这些字符出现在不带引号的 URI 中,则需要使用反斜杠进行转义,例如括号、逗号、空格字符、单引号 (') 和双引号 (") . 因此,您可能会发现最好在 URL 周围使用单引号或双引号。

请注意,您需要按以下格式编写完整的 CSS 属性:

background: url( http://example.com );

The URL bits of all three of your examples are valid CSS, according to the CSS specification.

Note that the spec identifies some characters in a URL which will need to be escaped with a backslash if present in an unquoted URI, such as parentheses, commas, white space characters, single quotes (') and double quotes ("). For this reason, you might find it better to use single or double quotes around your URLs.

Note that you need to write your full CSS property in the format:

background: url( http://example.com );
甜妞爱困 2024-08-24 04:28:16

我认为没有一个是对的。它应该是其中之一:

background: url(http://url)

background: url("http://url")

background: url('http://url')

注意冒号,而不是花括号。

I don't think any are right. It should be one of these:

background: url(http://url)

background: url("http://url")

background: url('http://url')

Note the colon, instead of curly braces.

垂暮老矣 2024-08-24 04:28:16

根据 W3 的说法,这是你的选择:

URI 值的格式为 'url('
后跟可选的空白
后跟可选的单引号
(') 或双引号 (") 字符
接下来是 URI 本身,然后是
通过可选的单引号 (') 或
双引号 (") 字符后跟
可选的空格,后跟“)”。
两个引号字符必须是
一样。

It is your choice, according to W3:

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.

云归处 2024-08-24 04:28:16

我用的是不带引号的。我记得读过 Zeldman 的一些文章,说它最不可能导致旧版浏览器出现问题。我相信他提到的浏览器很古老,比如 Netscape 2 之类的。如今,您使用哪种风格并不重要。

I use the one without quotes. I remember reading something by Zeldman that said it was the least likely to cause problems with legacy browsers. I believe the browser he mentioned was ancient, like Netscape 2 or something. Nowadays, it wouldn't matter which style you use.

冷了相思 2024-08-24 04:28:16

似乎任何引用或未引用的内容都是可以接受的(http://www.w3.org/ TR/css3-background/

但是下面这些仅当您引用域外的资源时才使用。

background: url(http://url)
background: url("http://url")
background: url('http://url')

如果您位于同一域:(如前所述,不需要“HTTP://”)

background: url(/path/to/file)
background: url("/path/to/file")
background: url('/path/to/file')

It seems any of the quoted or non quoted are acceptable (http://www.w3.org/TR/css3-background/)

BUT these below are only used IF you are referencing resource outside of your domain.

background: url(http://url)
background: url("http://url")
background: url('http://url')

IF you are on the same domain: (The "HTTP://" is not required, as previously mentioned)

background: url(/path/to/file)
background: url("/path/to/file")
background: url('/path/to/file')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文