--- id: bad87fee1348bd9aedf08807 title: Import a Google Font challengeType: 0 videoUrl: '' localeTitle: 导入Google字体 --- ## Description
除了指定在大多数操作系统上找到的常用字体外,我们还可以指定在我们的网站上使用的非标准自定义Web字体。互联网上有各种网络字体来源,但在本例中,我们将重点关注Google字体库。 Google字体是一个免费的网络字体库,您可以通过引用字体的URL在CSS中使用它。因此,让我们继续导入并应用Google字体(请注意,如果Google在您所在的国家/地区被屏蔽,则需要跳过此挑战)。要导入Google字体,您可以从Google字体库中复制字体网址,然后将其粘贴到HTML中。对于这个挑战,我们将导入Lobster字体。为此,请复制以下代码段并将其粘贴到代码编辑器的顶部(在开始style元素之前): <link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css">现在,您可以使用Lobster作为FAMILY_NAME在CSS中使用Lobster字体,如下例所示:
font-family: FAMILY_NAME, GENERIC_NAME; 。 GENERIC_NAME是可选的,如果其他指定的字体不可用,则为后备字体。这将在下一个挑战中得到体现。系列名称区分大小写,如果名称中有空格,则需要用引号括起来。例如,您需要引号才能使用"Open Sans"字体,但不能使用Lobster字体。
## Instructions
创建使用Lobster字体的font-family CSS规则,并确保它将应用于您的h2元素。
## Tests
```yml tests: - text: 导入Lobster字体。 testString: 'assert(new RegExp("googleapis", "gi").test(code), "Import the Lobster font.");' - text: 你的h2元素应该使用字体Lobster 。 testString: 'assert($("h2").css("font-family").match(/lobster/i), "Your h2 element should use the font Lobster.");' - text: 使用h2 CSS选择器更改字体。 testString: 'assert(/\s*h2\s*\{\s*font-family\:\s*(\"|")?Lobster(\"|")?\s*;\s*\}/gi.test(code), "Use an h2 CSS selector to change the font.");' - text: 你的p元素仍然应该使用字体monospace 。 testString: 'assert($("p").css("font-family").match(/monospace/i), "Your p element should still use the font monospace.");' ```
## Challenge Seed
```html

CatPhotoApp

Click here to view more cat photos.

A cute orange cat lying on its back.

Things cats love:

  • cat nip
  • laser pointers
  • lasagna

Top 3 things cats hate:

  1. flea treatment
  2. thunder
  3. other cats


```
## Solution
```js // solution required ```