在Google Fonts documentation , 它表明可以通过管道符 (|
) 来加载多个 Google 字体,例如:
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=PT+Sans:400,700|Amaranth:400italic" />
与 HTML validator ,它说:
Bad value http://fonts.googleapis.com/css?family=PT+Sans:400,700|Amaranth:400italic for attribute href on element link: Illegal character in query: | is not allowed.
我应该信任哪个网站?当然我可以像下面这样在两个请求中分离两种字体,但是加载时间会加倍。
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=PT+Sans:400,700" />
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Amaranth:400italic" />
附注DOCTYPE 是 HTML5。
最佳答案
正如@BoltClock 所建议的那样,将管道字符转义为 %7C
是最佳选择。
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=PT+Sans:400,700%7CAmaranth:400italic" />
两种字体均已正确加载,并通过上述链接的网络响应进行了验证。
关于html - 在 1 个请求中加载多个 Google 字体违反了 HTML 标准,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35788033/