This forum is now read-only. Please use our new forums! Go to forums
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
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.
Popular free courses
- Free Course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner friendly,4 LessonsLanguage Fluency - Free Course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner friendly,11 LessonsLanguage Fluency - Free Course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner friendly,6 LessonsLanguage Fluency
2 comments
Awesome, got it! Thank you very much for such a fast response!
in that case i spoiled some exercises for you :P you’re welcome