Help with CSS style

Tell us what’s happening:

Your code so far

  .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>

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Linux; Android 5.1; HTC Desire 828 dual sim Build/LMY47D) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.109 Mobile Safari/537.36.

Link to the challenge:
https://www.freecodecamp.org/challenges/use-a-css-class-to-style-an-element

2 Likes

The only problem I can find is the missing <style> element tag at the beginning. When I add that in, it passes.

3 Likes

I wrote it in the code, but here it did not appear it exist and despite that it gave me error

Where do you put your style tag?

In h2 tag to change its color to red

Did you try like this? it is worked for me

<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>

Yeah i want to do it like this

I don’t know how you wrote your html format anyways this is the correct way. Try it!

<!DOCTYPE html>
<html>
  <head>
    <style>
.red-text{
    color: red;
  }
</style>
  </head>
  <body>
    <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>
  </body>
</html>
1 Like

Thank you appreciate it

I did this i wrote the missing tags as you said to me and it didn’t change the color of the title CatPhotoApp to red

You welcome!
There is two ways to use CSS in html. The one we already used now , i.e. including css elements in style tag in the head tag of html. The other one we create a new css file and link this file with the html file. see this example:

External CSS
An external style sheet is used to define the style for many HTML pages.

With an external style sheet, you can change the look of an entire web site, by changing one file!

To use an external style sheet, add a link to it in the <head> section of the HTML page:

Example
<!DOCTYPE html>
<html>
<head>
  <link rel="stylesheet" href="styles.css">
</head>
<body>

<h1>This is a heading</h1>
<p>This is a paragraph.</p>

</body>
</html>
An external style sheet can be written in any text editor. The file must not contain any HTML code, and must be saved with a .css extension.

Here is how the "styles.css" looks:

body {
    background-color: powderblue;
}
h1 {
    color: blue;
}
p {
    color: red;
}
1 Like

Still it is not working?

Yes still not working i don’t why

did you copy all your code, then hit the “reset your code” button,
then paste your code back in & try again?

Can you open and see this? Do you want like this or?

1 Like

Yes i want exactly this output

No i didn’t try this way

Which browser do you use? google chrome or mozilla firefox or?

I am using chrome browser

close it and open it again.
or open in firefox if you have