2020-09-29 22:09:05 +02:00

3.2 KiB
Raw Blame History

id, title, challengeType, videoUrl, forumTopicId, localeTitle
id title challengeType videoUrl forumTopicId localeTitle
bad87fee1348bd9aecf08806 Use a CSS Class to Style an Element 0 https://scrimba.com/c/c2MvDtV 18337 使用 class 选择器设置单个元素的样式

Description

CSS 的class具有可重用性,可应用于各种 HTML 元素。 一个 CSSclass声明示例,如下所示:
<style>
  .blue-text {
    color: blue;
  }
</style>

可以看到,我们在<style>样式声明区域里,创建了一个名为blue-textclass选择器。 你可以将 CSSclass选择器应用到一个HTML元素里如下所示 <h2 class="blue-text">CatPhotoApp</h2> 注意:在style样式区域声明里,class需以.开头。而在 HTML 元素里,class属性的前面不能添加.

Instructions

style样式声明里,把h2元素选择器改为.red-textclass 选择器,同时将颜色blue变为red。 在h2元素里,添加一个class属性,且值为'red-text'

Tests

tests:
  - text: '<code>h2</code>元素应该为红色。'
    testString: assert($("h2").css("color") === "rgb(255, 0, 0)");
  - text: '<code>h2</code>元素应含有<code>red-text</code> class 选择器。'
    testString: assert($("h2").hasClass("red-text"));
  - text: '<code>style</code>样式声明区域里应该包含一个<code>red-text</code> class 选择器,并且它的颜色应为红色。'
    testString: assert(code.match(/\.red-text\s*\{\s*color\s*:\s*red;\s*\}/g));
  - text: '不要在<code>h2</code>元素里使用行内样式:<code>style="color&#58; red"</code>。'
    testString: assert($("h2").attr("style") === undefined);

Challenge Seed

<style>
  h2 {
    color: blue;
  }
</style>

<h2>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="https://freecatphotoapp.com/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