Stan
Stan

Reputation: 151

How to style elements with/without using class name

I have given a certain section a class name- 'section-team', like that: <section class= 'section-team'>. After that, I have been trying to style all the sections in my CSS document by using the selector .section, but it seems this call does not refer to the section that was called 'section-team' anymore, and in order to style this particular section, I have to use .section-team. Is that a feature of the language or am I doing something wrong?

Upvotes: 0

Views: 1124

Answers (1)

AndrewL64
AndrewL64

Reputation: 16311

The dot is for targeting class names in CSS. .section unlike section will try to find any element that has the class name section like:

<div class="section">Some Content</div>
<section class="section">Some More Content</section>
<p class="section">Some Other Content</p>

If you want to target all section elements including the one with the class name "section-team", you can do this:

section {
   color: #000;    
}

And if you want to target just the section-team section, you can do this:

.section-team {
    color: #222;
}

Upvotes: 1

Related Questions