Files
freeCodeCamp/curriculum/challenges/ukrainian/01-responsive-web-design/basic-css/use-a-css-class-to-style-an-element.md

4.3 KiB
Raw Permalink Blame History

id, title, challengeType, videoUrl, forumTopicId, dashedName
id title challengeType videoUrl forumTopicId dashedName
bad87fee1348bd9aecf08806 Використання класу CSS для стилізації елементів 0 https://scrimba.com/c/c2MvDtV 18337 use-a-css-class-to-style-an-element

--description--

Класи - це повторно використовувані стилі, котрі можуть бути доданими в елементи HTML.

Ось приклад об'яви класу CSS:

<style>
  .blue-text {
    color: blue;
  }
</style>

Ви можете побачити, що ми створили клас CSS під назвою blue-text в межах тегу <style>. Ви можете застосувати клас до елемента HTML ось так: <h2 class="blue-text">CatPhotoApp</h2>. Зверніть увагу, що в елементі CSS style, назви класів починаються з крапки. В атрибуті класу елемента HTML назва класу не містить крапки.

--instructions--

Всередині елемента style, змініть селектор h2 на .red-text й оновіть значення кольору з blue на red.

Задайте елементу h2 атрибут class зі значенням red-text.

--hints--

Елемент h2 повинен бути червоним.

assert($('h2').css('color') === 'rgb(255, 0, 0)');

Елемент h2 повинен мати клас red-text.

assert($('h2').hasClass('red-text'));

Таблиця стилів повинна об'явити клас red-text і встановити його колір на red (червоний).

assert(code.match(/\.red-text\s*\{\s*color\s*:\s*red;?\s*\}/g));

Ви не повинні використовувати вбудовані об'яви стилів, такі як style="color: red" в елементі h2.

assert($('h2').attr('style') === undefined);

--seed--

--seed-contents--

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

<h2>CatPhotoApp</h2>
<main>
  <p>Click here to view more <a href="#">cat photos</a>.</p>

  <a href="#"><img src="https://cdn.freecodecamp.org/curriculum/cat-photo-app/relaxing-cat.jpg" alt="A cute orange cat lying on its back."></a>

  <div>
    <p>Things cats love:</p>
    <ul>
      <li>cat nip</li>
      <li>laser pointers</li>
      <li>lasagna</li>
    </ul>
    <p>Top 3 things cats hate:</p>
    <ol>
      <li>flea treatment</li>
      <li>thunder</li>
      <li>other cats</li>
    </ol>
  </div>

  <form action="https://freecatphotoapp.com/submit-cat-photo">
    <label><input type="radio" name="indoor-outdoor" checked> Indoor</label>
    <label><input type="radio" name="indoor-outdoor"> Outdoor</label><br>
    <label><input type="checkbox" name="personality" checked> Loving</label>
    <label><input type="checkbox" name="personality"> Lazy</label>
    <label><input type="checkbox" name="personality"> Energetic</label><br>
    <input type="text" placeholder="cat photo URL" required>
    <button type="submit">Submit</button>
  </form>
</main>

--solutions--

<style>
  .red-text {
    color: red;
  }
</style>

<h2 class="red-text">CatPhotoApp</h2>
<main>
  <p>Click here to view more <a href="#">cat photos</a>.</p>

  <a href="#"><img src="https://cdn.freecodecamp.org/curriculum/cat-photo-app/relaxing-cat.jpg" alt="A cute orange cat lying on its back."></a>

  <div>
    <p>Things cats love:</p>
    <ul>
      <li>cat nip</li>
      <li>laser pointers</li>
      <li>lasagna</li>
    </ul>
    <p>Top 3 things cats hate:</p>
    <ol>
      <li>flea treatment</li>
      <li>thunder</li>
      <li>other cats</li>
    </ol>
  </div>

  <form action="https://freecatphotoapp.com/submit-cat-photo">
    <label><input type="radio" name="indoor-outdoor" checked> Indoor</label>
    <label><input type="radio" name="indoor-outdoor"> Outdoor</label><br>
    <label><input type="checkbox" name="personality" checked> Loving</label>
    <label><input type="checkbox" name="personality"> Lazy</label>
    <label><input type="checkbox" name="personality"> Energetic</label><br>
    <input type="text" placeholder="cat photo URL" required>
    <button type="submit">Submit</button>
  </form>
</main>