:nth-of-type(1) css not working

I have two empty divs name

<div class="empty"></div>
        <div class="empty"></div>

, in my html code since they’re same I tried to select the first one using empty:nth-of-type(1) but it didn’t do the job, the styles I added were ignored.

I was expecting using empty:nth-of-type(1) will let me control the css of the first empty class div but it didn’t, I can normally add css by doing .empty {}. Maybe I’m using it in a wrong way, let me know thanks!

In this clone spotify login page which I’m working on right now.

Check line no. 50, 51 on html file, there will be two divs with class name as “empty” and in the css check line number 392 where I’m targetting the html element but seems not working Thanks.

Hello and welcome back to the forum @Pravin !

It is important to remember to place the css class selector which uses a . before the class name.

Example

<div class="code"></div>

for css

.code{
width: 6px;
}

I cannot see your code but noticed in your post that the . was missing before empty. 

Wishing you good progress on your coding path. :slightly_smiling_face:
1 Like

I understand how you come up with this but I was just saying what I was using, for example :nth-of-type(1), I wasn’t implying the exact thing I written in code, I was just explaining what I’m trying to do, can you look up in codepen I’ve mentioned the line number and everything, and there I indeed used “.” before class name

also is my code private? is that why you can’t see it, this is my first sharing it, so maybe that’s the reason I guess

1 Like

Sorry for misunderstanding. As I said, I cannot view your code, as I only have freecodecamp.

Wishing you good progress on your coding path. :slightly_smiling_face:

Codepen is visible without an account @StaySilent


Your issue @Pravin is that nth-of-type works with tag names, not classes

1 Like

Thank you for this information. I never realized that a person could view content without an account.

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