Comments on: :nth-of-type https://css-tricks.com Tips, Tricks, and Techniques on using Cascading Style Sheets. Fri, 05 Nov 2021 20:00:02 +0000 hourly 1 https://wordpress.org/?v=6.1.1 By: Ully https://css-tricks.com/almanac/selectors/n/nth-of-type/#comment-1756796 Tue, 19 May 2020 00:04:33 +0000 http://css-tricks.com/?page_id=14234#comment-1756796 Thank you!! I was having a hard time to understand this selector, thank you very much!

]]>
By: Nathan https://css-tricks.com/almanac/selectors/n/nth-of-type/#comment-1741588 Sun, 07 Jul 2019 22:11:05 +0000 http://css-tricks.com/?page_id=14234#comment-1741588 This may sound silly, but how does nth-of-type deal with gaps in the count? Say my code is

li.count-me:nth-of-type(2n+1){ background-color: #F00; }

Surely then my CSS should work as follows:

<li class="count-me">I should be red</li>
<li class="count-me">I should not be red</li>
<li class="count-me">I should be red</li>
<li class="donot-count-me">I should be ignored</li>
<li class="count-me">I should not be red</li>
<li class="count-me">I should be red</li>

Yet, when I have tried it, the final two <li>s are the opposite of what they should theoretically be – the one that should not be red is, and the one that should be red is not. Is there a way of having CSS ignore the gaps, or skip over the elements it should not count (in this example, the ones that do not have the class of .count-me)?

]]>
By: Avi Drucker https://css-tricks.com/almanac/selectors/n/nth-of-type/#comment-1612812 Fri, 03 Nov 2017 00:19:47 +0000 http://css-tricks.com/?page_id=14234#comment-1612812 In reply to Andreas Ibsen.

Thanks for this!

]]>
By: Brad Dalton https://css-tricks.com/almanac/selectors/n/nth-of-type/#comment-1611768 Wed, 13 Sep 2017 17:12:17 +0000 http://css-tricks.com/?page_id=14234#comment-1611768 You can use nth-child and nth-of-type like this :
`
.post:nth-of-type {}

.post:nth-child {}
`

]]>
By: Sterling https://css-tricks.com/almanac/selectors/n/nth-of-type/#comment-1606092 Thu, 12 Jan 2017 16:55:37 +0000 http://css-tricks.com/?page_id=14234#comment-1606092 In reply to Sterling.

Alright I found what I was missing. Seems to always happen after I ask somewhere. The n appears to be evaluating at 0 but the div count is a 1 indexed. Have I correctly corrected myself?

]]>
By: Sterling https://css-tricks.com/almanac/selectors/n/nth-of-type/#comment-1606090 Thu, 12 Jan 2017 16:05:29 +0000 http://css-tricks.com/?page_id=14234#comment-1606090 This appears to be use a 1 index rather than a 0 index. Playing with this in my own code as well as just modifying the codepen example, 0 is never evaluated. Am i missing something somewhere or has this changed since the original posting?

]]>
By: qqq https://css-tricks.com/almanac/selectors/n/nth-of-type/#comment-1601388 Fri, 06 May 2016 05:55:04 +0000 http://css-tricks.com/?page_id=14234#comment-1601388 niiiiiiiiiiiiiiiiiiiiiiiiiiiiicccccccccccccccccccccceeeeeeeeeeeeeeeeee

]]>
By: Andreas Ibsen https://css-tricks.com/almanac/selectors/n/nth-of-type/#comment-1596051 Thu, 23 Jul 2015 11:55:56 +0000 http://css-tricks.com/?page_id=14234#comment-1596051 Perhaps it should be clarified that this selector only pertains to types/tags (div, p, span, etc.) not .class?

]]>
By: c https://css-tricks.com/almanac/selectors/n/nth-of-type/#comment-1593299 Fri, 20 Mar 2015 12:10:02 +0000 http://css-tricks.com/?page_id=14234#comment-1593299 Splendid, thank you.

]]>
By: blwoosky https://css-tricks.com/almanac/selectors/n/nth-of-type/#comment-557724 Tue, 24 Sep 2013 01:58:04 +0000 http://css-tricks.com/?page_id=14234#comment-557724 In reply to blwoosky.

sorry,i am wrong~~

]]>
By: blwoosky https://css-tricks.com/almanac/selectors/n/nth-of-type/#comment-557689 Tue, 24 Sep 2013 01:34:37 +0000 http://css-tricks.com/?page_id=14234#comment-557689 n should start from 1

]]>