2018-10-10 18:03:03 -04:00
---
id: bad87fee1348bd9aecf08806
title: Use a CSS Class to Style an Element
challengeType: 0
2019-08-28 16:26:13 +03:00
videoUrl: https://scrimba.com/c/c2MvDtV
forumTopicId: 18337
2019-04-22 23:39:40 +06:00
localeTitle: Используйте селектор класса в CSS для стилизации элемента
2018-10-10 18:03:03 -04:00
---
## Description
2019-08-28 16:26:13 +03:00
<section id='description'>
Классы - многоразовые стили, которые можно добавить к элементам HTML. Вот пример объявления класса CSS: <blockquote> <style> <br> .blue-text { <br> color: blue; <br> } <br> </ style> </blockquote> Вы можете видеть, что мы создали класс CSS, который назвали <code>blue-text</code> в <code><style></code> . Вы можете применить класс к HTML-элементу следующим образом: <code><h2 class="blue-text">CatPhotoApp</h2></code> Обратите внимание, что в элементе <code>style</code> CSS имена классов начинаются с точки. В атрибуте класса HTML-элементов имя класса не включает точку.
</section>
2018-10-10 18:03:03 -04:00
## Instructions
2019-08-28 16:26:13 +03:00
<section id='instructions'>
Внутри элемента <code>style</code> измените селектор <code>h2</code> на <code>.red-text</code> и обновите значение цвета с <code>blue</code> на <code>red</code> . Задайте вашему элементу <code>h2</code> атрибут <code>class</code> с о значением <code>' ;red-text' ;</code> .
</section>
2018-10-10 18:03:03 -04:00
## Tests
<section id='tests'>
```yml
tests:
2019-08-28 16:26:13 +03:00
- text: Your <code>h2</code> element should be red.
testString: assert($("h2").css("color") === "rgb(255, 0, 0)");
- text: Your <code>h2</code> element should have the class <code>red-text</code>.
testString: assert($("h2").hasClass("red-text"));
- text: Your stylesheet should declare a <code>red-text</code> class and have its color set to red.
testString: assert(code.match(/\.red-text\s*\{\s*color\s*:\s*red;\s*\}/g));
- text: Do not use inline style declarations like <code>style="color: ; red"</code> in your <code>h2</code> element.
testString: assert($("h2").attr("style") === undefined);
2018-10-10 18:03:03 -04:00
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='html-seed'>
```html
<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://bit.ly/fcc-relaxing-cat" 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>
2020-07-15 02:54:34 -07:00
<form action="https://freecatphotoapp.com/submit-cat-photo">
2018-10-10 18:03:03 -04:00
<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>
```
</div>
</section>
## Solution
<section id='solution'>
2019-08-28 16:26:13 +03:00
```html
<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://bit.ly/fcc-relaxing-cat" 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>
2020-07-15 02:54:34 -07:00
<form action="https://freecatphotoapp.com/submit-cat-photo">
2019-08-28 16:26:13 +03:00
<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>
2018-10-10 18:03:03 -04:00
```
2019-08-28 16:26:13 +03:00
2018-10-10 18:03:03 -04:00
</section>