0

I have this code and I can't figure out why the nth-of-type selector needs to be 2, not 1, for the first sibling of this type.

Here's a jsfiddle code: https://jsfiddle.net/xj5hvn16/

Can someone, please, explain this to me?

.flowbox .utm_registrars_code:nth-of-type(2) {
  background-color: red;
}
<div class="flowbox freebox">
  <div class="pholdcard18"></div>
  <div class="flowcard14 utm_registrars_code">
    <div class="content">
      Content 1
    </div>
  </div>
  <div class="flowcard14 utm_registrars_code">
    <div class="content">
      Content 2
    </div>
  </div>
  <div class="flowcard14 utm_registrars_code">
    <div class="content">
      Content 3
    </div>
  </div>
</div>
mplungjan
  • 169,008
  • 28
  • 173
  • 236
ivanacorovic
  • 2,669
  • 4
  • 30
  • 46

2 Answers2

1

nth-of-type does not mean nth-of-class!

The first element of type div is

<div class="pholdcard18"></div>   

Hence your Content 1 element is the second and highlighted.

Sirko
  • 72,589
  • 19
  • 149
  • 183
1

That is because nth-of-type starts with the first element of a certain type, in your case a div, and not the first element with the selected class

The :nth-of-type() pseudo-class represents an element that has an+b siblings with the same expanded element name before it in the document tree, for any zero or positive integer value of n, and has a parent element.

More info:

Asons
  • 84,923
  • 12
  • 110
  • 165