html - 根据 W3C,使用 Google 字体 : however, 代码不是有效的 HTML5?

标签 html validation fonts

<分区>

我正在做一项作业,我正在为我的网站使用 Google 字体。我正在尝试使用 W3C 验证我的 HTML,因为我的作业必须有效才能获得满分,而且我一直收到 Google 字体代码错误。我似乎无法弄清楚为什么。这是代码:

<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Orbitron|Special+Elite|Open+Sans">

这是我从 W3C 收到的错误消息:

Bad value http://fonts.googleapis.com/css?family=Orbitron|Special+Elite|Open+Sans for attribute href on element link: Illegal character in query: not a URL code point.

…href="http://fonts.googleapis.com/css?family=Orbitron|Special+Elite|Open+Sans">

Syntax of IRI reference: Any URL. For example: /hello, #canvas, or http://example.org/. Characters should be represented in NFC and spaces should be escaped as %20.

有什么想法吗?我是 HTML5 的新手,所以我不确定我在这里遗漏了什么。

最佳答案

这里的违规字符是“|” U+007C VERTICAL LINE,被谷歌用作字体名称之间的分隔符;这是他们的错误选择,因为“|”是保留字符,均由“URL Living Standard” (这是 HTML5 CR 引用的内容)和互联网标准 STD 66 ( RFC 3986 )。

在实践中,当你使用“|”时效果很好因此,但为了符合标准和草案,对其使用百分比编码(% 编码,如 URL 规范中所定义),改为编写 %7c(不区分大小写):

<link rel="stylesheet" type="text/css" href=
"http://fonts.googleapis.com/css?family=Orbitron%7cSpecial+Elite%7cOpen+Sans">

关于html - 根据 W3C,使用 Google 字体 : however, 代码不是有效的 HTML5?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22926986/

相关文章:

javascript - 如何在 JavaScript 中检查元素是否已附加

javascript - CodeMirror 动态语法验证

CSS:字体上边距

java - 如果缺少 PDF 字体,为什么 jasper 报告不抛出 JRFontNotFoundException?

javascript - 我找不到 javascript 代码在哪里

html - 如何设置一个 div 使用一定百分比的高度,同时使用溢出 :auto to put a scrollbar?

导航栏中的 html/css 下拉列表没有出现

ruby-on-rails - Rails 不在关联模型上显示验证错误消息

使用单选按钮和数组进行 Javascript 测试

Java8 ArchLinux arm 字体 NullPointerException