Css nth-of-type problem

to ask a question, please see the code:

target5</span>
  </div>
</body>

</html>
The goal of

is to select the 2n any element with a .target class name, that is, target2, target4

if you use .target: nth-of-type (2n) , this selector indicates this is the 2n span, of the parent element with target class , and target2 is the third span, so it is not selected.

if you use .target:nth-child (2n) , this selector represents the 2n element of the parent element, with target class . Causes the sixth and eighth elements of the parent element, target3 and target5, to be selected, and the seventh element, target4, to be unselected.

is there any other way to use only css without moving html,?

Oct.28,2021

first of all, if html, only uses css, there is no solution
because the content you choose is based on the text content in the tag, and the css selector cannot match the text information in the tag
since you want to match the element whose tag content is target [2n] , why not just add a unified class name to its span tag?

Menu