Learn CSS Colors by Building a Set of Colored Markers - Step 18

I already have the answer, im just wondering why sometimes its “one” and other times its “.one” i thought the “.” was added before a selector if it was a new class that hadnt been added to the index,html yet but it seems to be more situational than that?

  **Your code so far**
/* file: index.html */
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Colored Markers</title>
  <link rel="stylesheet" href="styles.css">
</head>
<body>
  <h1>CSS Color Markers</h1>
  <div class="container">
    <div class="marker one">
    </div>
    <div class="marker">
    </div>
    <div class="marker">
    </div>
  </div>
</body>
</html>
/* file: styles.css */
h1 {
text-align: center;
}

.marker {
width: 200px;
height: 25px;
margin: 10px auto;
}

one {
background-color: red;
}

  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.102 Safari/537.36 Edg/104.0.1293.63

Challenge: Learn CSS Colors by Building a Set of Colored Markers - Step 18

Link to the challenge:

Hi,

This code should not be passing. Has it passed when you press the ‘check your code’ button?

A css class referenced in a html file should always have the . in front of it.

no it told me it was wrong until i put . in front of “one” but when is it right to put the . in front and when should i not use the .

You should use . when you are using class.

ok i get it now, so we dont use the . when the class hasn’t been specified in the index.html yet right?

1 Like

Yep you are right. Same goes with id you only use # when you’re using id.

Sorry i forgot we had already set the class for one, it was specified with the other class marker in the same div so i completely looked over it, it was


i was looking for a <div class=“one”

Always use the dot in front of a css class selector.

However, selectors like h1, p, img are not css classes. Do not put a dot in front when writing them in css.

1 Like

Yes!! That exactly what confused me thats why i was wondering what the rules were for that, in a few of the other steps i put . in front of h1 and img and it wouldnt accept it . Thats when i first noticed the “inconsistencies”, but i just didnt understand it. Thank you Ella!

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.