This forum is now read-only. Please use our new forums! Go to forums

0 points
Submitted by Ira M
over 8 years

Is there supposed to be a dot (.) before a selector in stylesheet.css ?

Hi there,

in one of the courses I took (maybe it was “Creating a website?”) when you write a selector in .css - I remember in the example we are supposed to put a DOT (.) in front of it, e.g.

.selector {
property:value;
}

In the class I’m taking now (CSS 8/26) - there is no dot before the selector. Am I confused or it doesn’t matter for correct syntax?

Thank you!

Answer 55fa7e8ae39efe84ec0001a6

0 votes

Permalink

Well, yes and no.

if i have a paragraph:

<p>i am a paragraph</p>

and i want to changes it color in css, i don’t use a dot:

p {
  color: green;
}

now let’s say i have a whole of paragraph and i don’t want to color all of them green, i can use classes:

<p class="green">i am going to be green</p>
<p>i am a paragraph</p>
<p class="green">i am going to be green</p>
<p>i am a paragraph</p>

now, to tell css we have a class, we use the dot:

.green {
  color: green;
}

now only the elements with class green, become green.

So, recap: to select a html element, the css selector is without a dot, if you need to select a class, you use the dot. This will be covered later in this track. I hope i answered your question.

points
Submitted by stetim94
over 8 years

2 comments

Ira M over 8 years

Awesome, got it! Thank you very much for such a fast response!

stetim94 over 8 years

in that case i spoiled some exercises for you :P you’re welcome