Files
freeCodeCamp/curriculum/challenges/chinese/01-responsive-web-design/basic-css/specify-how-fonts-should-degrade.chinese.md
2020-02-11 15:42:42 +09:00

3.6 KiB
Raw Blame History

id, title, challengeType, videoUrl, forumTopicId, localeTitle
id title challengeType videoUrl forumTopicId localeTitle
bad87fee1348bd9aedf08808 Specify How Fonts Should Degrade 0 https://scrimba.com/c/cpVKBfQ 18304 字体如何优雅降级

Description

所有浏览器都有几种默认字体。这些通用字体包括monospaceserifsans-serif。 当字体不可用,你可以告诉浏览器通过 “降级” 去使用其他字体。 例如,如果你想将一个元素的字体设置成Helvetica,当Helvetica不可用时,降级使用sans-serif字体,那么可以这样写:
p {
  font-family: Helvetica, sans-serif;
}

通用字体名字不区分大小写。同时,也不需要使用引号,因为它们是 CSS 关键字。

Instructions

首先,添加monospace字体到h2元素里,它现在拥有着Lobstermonospace两种字体。 在上一个挑战里,你已经通过link标签引入谷歌Lobster字体。现在让我们注释掉谷歌Lobster字体的引入(使用我们之前学过的HTML注释),使字体失效。你会发现h2元素降级到了monospace字体。 注意:
如果电脑已经安装了Lobster字体,你将看不到这个降级过程,因为浏览器会找到该字体。

Tests

tests:
  - text: '<code>h2</code>元素应该含有<code>Lobster</code>字体。'
    testString: assert($("h2").css("font-family").match(/^"?lobster/i));
  - text: '当<code>Lobster</code>字体失效时,<code>h2</code>元素应该降级使用<code>monospace</code>字体。'
    testString: 'assert(/\s*h2\s*\{\s*font-family\:\s*(\''|")?Lobster(\''|")?,\s*monospace\s*;\s*\}/gi.test(code));'
  - text: '通过添加<code>&#60!--</code>,注释掉谷歌<code>Lobster</code>字体的引入。'
    testString: assert(new RegExp("<!--[^fc]", "gi").test(code));
  - text: '确保注释要以<code>--&#62;</code>结束。'
    testString: assert(new RegExp("[^fc]-->", "gi").test(code));

Challenge Seed

<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css">
<style>
  .red-text {
    color: red;
  }

  h2 {
    font-family: Lobster;
  }

  p {
    font-size: 16px;
    font-family: monospace;
  }
</style>

<h2 class="red-text">CatPhotoApp</h2>
<main>
  <p class="red-text">点击查看更多<a href="#">猫图</a>.</p>
  
  <a href="#"><img src="https://bit.ly/fcc-relaxing-cat" alt="一只仰卧着的萌猫"></a>
  
  <div>
    <p>猫咪最喜欢的三件东西:</p>
    <ul>
      <li>猫薄荷</li>
      <li>激光笔</li>
      <li>千层饼</li>
    </ul>
    <p>猫咪最讨厌的三件东西:</p>
    <ol>
      <li>跳蚤</li>
      <li>打雷</li>
      <li>同类</li>
    </ol>
  </div>
  
  <form action="/submit-cat-photo">
    <label><input type="radio" name="indoor-outdoor">室内</label>
    <label><input type="radio" name="indoor-outdoor">室外</label><br>
    <label><input type="checkbox" name="personality">忠诚</label>
    <label><input type="checkbox" name="personality">懒惰</label>
    <label><input type="checkbox" name="personality">积极</label><br>
    <input type="text" placeholder="猫咪图片地址" required>
    <button type="submit">提交</button>
  </form>
</main>

Solution

// solution required