S
S
snap442018-08-04 22:14:35
css
snap44, 2018-08-04 22:14:35

:nth-child not counting elements correctly?

There is markup

<span>1</span>
  <span>2</span>
  <span>3</span>
  <span>4</span>
  <span>5</span>
  <span>6</span>
  <span>7</span>
  <span>8</span>
  <span>9</span>
  <span>10</span>

And sass styles
span
  width: 40px
  height: 40px
  border-radius: 5px
  background: #F8A25D
  display: inline-flex
  justify-content: center
  align-items: center
  font-family: Arial, "Helvetica Neue", Helvetica, sans-serif
  color: #333
  font-weight: bold

  &:nth-child(3n + 2)
    border-radius: 50%

All this quite predictably selects every third element starting from the second result
The magic starts if you open this code on the local. The result will be like this
5b65fa58a804b950814359.png
. The developer panel says that the selector worked. But it didn't work right. The markup is the same as in the codepen (except for the doctype and that's it). What the hell is going on?
5b65fb140c524863626108.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2018-08-04
@snap44

Scripts are also children, so browsersync spoils your raspberries. You need nth-of-type, not nth-child.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question