Using a class in CSS to change the color of HTML heading (h2)

Using a class in CSS to change the color of HTML heading (h2)
0

#1

Tell us what’s happening:
I am attempting to make h2 red using class script. In the section I have designated the class of red using .red-text, but how do I make this apply to h2?

Your code so far


<style>
 .red-text {
    color: red;
  }
</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>
  
  <form action="/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>

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.16 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/responsive-web-design/basic-css/use-a-css-class-to-style-an-element


#2

You can apply styles in two ways. the first way and the way the tutoriual wants you to do is is make the

.red-text{

}

declaration and the apply the rules of the .red-text declaration at a tag. The way you do it is by passing a class attribute to h2 tag -->

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

Every tag that you will add the .red-text class will apply the rules inside of that class to the tag. so anywhere you add

class="red-text" the text will become red.


#3

Thanks for your help with this but I am still a bit lost.
-It seems my style sheet is correct but I am having trouble making the class .red-text effect h2

In order to make h2 red do I need to amend my style guide or is this done within h2?


#4

The .red-text declaration you made will make any tag with

class=“red-text” turn red

so you just need to do this

<h2 class="red-text"></h2> to turn the text red


#5

Thank you so much for your help!