FCC Challenge 10: Use a CSS Class to Style an Element

In FCC Challenge 10, you’re required to change the style selector to .red-text and the color to red. At the same time the ‘red-text’ class should be appended to the h2 element:

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

<h2>CatPhotoApp</h2>

<p>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>

The modified code should be:

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

<h2 class="red-text">CatPhotoApp</h2>

<p>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>

Classes are reusable styles that can be added to HTML elements.

Here’s an example CSS class declaration:

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

You can see that we’ve created a CSS class called blue-text within the <style> tag.

You can apply a class to an HTML element like this:

<h2 class="blue-text">CatPhotoApp</h2>

Note that in your CSS style element, classes should start with a period. In your HTML elements’ class declarations, classes shouldn’t start with a period.

Inside your style element, change the h2 selector to .red-text and update the color’s value from blue to red.

Give your h2 element the class attribute with a value of ‘red-text’.

Leave a Comment