--- id: bad87fee1348bd9aedd08845 title: 在按钮中添加字体图标 challengeType: 0 forumTopicId: 16638 required: - link: 'https://use.fontawesome.com/releases/v5.8.1/css/all.css' raw: true dashedName: add-font-awesome-icons-to-our-buttons --- # --description-- Font Awesome 是一个非常便利的图标库。 这些图标可以是网络字体,也可以是一张矢量图。 这些图标就和字体一样, 不仅能通过像素单位指定它们的大小,它们也同样会继承父级 HTML 元素的字体大小。 可以将 Font Awesome 图标库添加至任何一个 web app 中,方法很简单,只需要在 HTML 头部增加下列代码即可: `` 不过在这里,已经预先为此页面添加了上述代码。 `i` 元素起初用于让其它元素具有斜体(italic)的效果,不过现在一般用于显示图标。 可以把 Font Awesome 中的 class 属性添加到 `i` 元素中,让它变成一个图标,比如: `` 注意用 `span` 元素展示图标也是可以的。 # --instructions-- 给 like 按钮添加一个 Font Awesome `thumbs-up` 图标,具体方法是给 `i` 元素添加 `fas` 和 `fa-thumbs-up` class 属性。 确保将 `Like` 文本放在图标旁边。 # --hints-- 增加一个 class 为 `fas` 和 `fa-thumbs-up` 的 `i` 元素。 ```js assert($('i').is('.fas.fa-thumbs-up') || $('span').is('.fas.fa-thumbs-up')); ``` `fa-thumbs-up` 图标应该在 Like 按钮中。 ```js assert( ($('i.fa-thumbs-up').parent().text().match(/Like/gi) && $('.btn-primary > i').is('.fas.fa-thumbs-up')) || ($('span.fa-thumbs-up').parent().text().match(/Like/gi) && $('.btn-primary > span').is('.fas.fa-thumbs-up')) ); ``` `i` 元素应该在 `button` 元素中。 ```js assert( $('button').children('i').length > 0 || $('button').children('span').length > 0 ); ``` 确保图标元素有一个闭合标签。 ```js assert(code.match(/<\/i>|<\/span>/g)); ``` # --seed-- ## --seed-contents-- ```html

CatPhotoApp

A cute orange cat lying on its back.
Three kittens running towards the camera.

Things cats love:

Top 3 things cats hate:

  1. flea treatment
  2. thunder
  3. other cats
``` # --solutions-- ```html

CatPhotoApp

A cute orange cat lying on its back.
Three kittens running towards the camera.

Things cats love:

Top 3 things cats hate:

  1. flea treatment
  2. thunder
  3. other cats
```