Comments on: :nth-child https://css-tricks.com Tips, Tricks, and Techniques on using Cascading Style Sheets. Sun, 25 Dec 2022 12:12:46 +0000 hourly 1 https://wordpress.org/?v=6.4.3 By: Bolbo na https://css-tricks.com/almanac/selectors/n/nth-child/#comment-1798169 Sun, 25 Dec 2022 12:12:46 +0000 http://css-tricks.com/?page_id=14230#comment-1798169 Is there any way to select 3 to last element?

]]>
By: Carlos https://css-tricks.com/almanac/selectors/n/nth-child/#comment-1789185 Fri, 04 Feb 2022 12:44:17 +0000 http://css-tricks.com/?page_id=14230#comment-1789185 Are display:none elements, selectable with this selector?

]]>
By: chnce https://css-tricks.com/almanac/selectors/n/nth-child/#comment-1756758 Mon, 18 May 2020 00:10:52 +0000 http://css-tricks.com/?page_id=14230#comment-1756758 so what if you have to select the but within a particular limit for example from element 5 to element 10?? then how can you do it?

]]>
By: Chris Coyier https://css-tricks.com/almanac/selectors/n/nth-child/#comment-1755628 Wed, 08 Apr 2020 14:27:23 +0000 http://css-tricks.com/?page_id=14230#comment-1755628 In reply to Martin Parenteau.

It’s 1

]]>
By: Martin Parenteau https://css-tricks.com/almanac/selectors/n/nth-child/#comment-1755627 Wed, 08 Apr 2020 14:02:32 +0000 http://css-tricks.com/?page_id=14230#comment-1755627 It would be nice to mention if the index of the first element is 0 or 1. I don’t use these selectors every day and, every time I have to use them, I look for that information, including here. Thanks!

]]>
By: Matej Mulej https://css-tricks.com/almanac/selectors/n/nth-child/#comment-1753193 Fri, 20 Dec 2019 10:19:23 +0000 http://css-tricks.com/?page_id=14230#comment-1753193 In reply to touhid_rahman.

This works great if all the children are of the same type (element, class…):
.parent>.child:nth-last-child(-n+3) { /* selected last three elements with class=”child” that are direct children of elements with class=”parent” */ } or just
.child:nth-last-child(-n+3) { /* selected last three children with class=”child” */ }

:nth-last-child

Problem is when there are different children, and you only want to select last few of a subgroup of them with the same class.

This :nth-last-child(-n+3 of selector) let’s you select even by class, but sadly it isn’t supported anywhere but in Safari.

I’m not sure how to do it for .class for all browsers, but I tend to solve this with element tags if posssible:

Subtitle

Text1

Text2

Text3

Text4

Made by

.parent>section:nth-last-of-type(-n+3) { /* select last three section elements that are direct children of elements with class=”parent” */ } (stupid example, I know..)

:nth-last-of-type

]]>
By: Sunshiney https://css-tricks.com/almanac/selectors/n/nth-child/#comment-1751120 Sat, 31 Aug 2019 19:46:26 +0000 http://css-tricks.com/?page_id=14230#comment-1751120 Given all the unanswered questions here — and me wanting to post yet another question — maybe add a link here to slackexchange or a separate forum as the questions get lost when after the posts? idk. Just thinking. But not going to post my question!! lol

]]>
By: Gabriel Pinto-Hasagiv https://css-tricks.com/almanac/selectors/n/nth-child/#comment-1750481 Fri, 02 Aug 2019 22:39:57 +0000 http://css-tricks.com/?page_id=14230#comment-1750481 How i can controll the font color when i’m setting this css?

]]>
By: Aakash https://css-tricks.com/almanac/selectors/n/nth-child/#comment-1727217 Fri, 21 Jun 2019 10:43:41 +0000 http://css-tricks.com/?page_id=14230#comment-1727217 I would like to know if there is a way i can target the 2nd class, when there are 2 classes of the same name.

I have 2 instances of media-link contained withing a DIV called item. I need to basically add additional styles to the 2nd instance of the class. However this is where the difficulty comes in… I can not add any additional code, or classes to the code! I know, not ideal but its down to the solution being used, not personal choice.

Example code:


Author: John Smith

]]>
By: Christian Thorne https://css-tricks.com/almanac/selectors/n/nth-child/#comment-1663291 Sun, 10 Feb 2019 11:54:33 +0000 http://css-tricks.com/?page_id=14230#comment-1663291 Hello,

Thanks for a great article…

I am trying to figure out of if there is a formula, that would focus on one column independent of all other columns or rows, for example, using the grid analogy, the first cell in a grid could be given a different width to the other cells?

Thanks.

]]>
By: david stanton https://css-tricks.com/almanac/selectors/n/nth-child/#comment-1651829 Fri, 31 Aug 2018 09:01:43 +0000 http://css-tricks.com/?page_id=14230#comment-1651829 hi, i’m trying to place some divs after ever X amount of P, can I use this to do that. I have this which sort of works, but it puts some “random” Advertisement header in funny places and it doesnt seem to place the items in the order i put them (1,2,3,4), $(document).ready(function(){
$(‘

Advertisement

‘).insertAfter(‘#mvp-content-main p:nth-child(2)’);
$(‘

Advertisement

‘).insertAfter(‘#mvp-content-main p:nth-child(5)’);
$(‘

Advertisement

‘).insertAfter(‘#mvp-content-main p:nth-child(10)’);
$(‘

Advertisement

‘).insertAfter(‘#mvp-content-main p:nth-child(18)’);

]]>
By: touhid_rahman https://css-tricks.com/almanac/selectors/n/nth-child/#comment-1613980 Sun, 24 Dec 2017 17:12:14 +0000 http://css-tricks.com/?page_id=14230#comment-1613980 How can I select specific number of last child using CSS?

For example, there are total 12 elements. I want to apply my style only on last n (1, 2, 3…) numbers of child of total 12 elements; how can I do this?

]]>
By: Rohith https://css-tricks.com/almanac/selectors/n/nth-child/#comment-1606462 Wed, 01 Feb 2017 08:25:02 +0000 http://css-tricks.com/?page_id=14230#comment-1606462 Hi,

The Phrase ” But the keywords or a formula will iterate through all the children of the parent element and select matching elements ”

is this also right as per my understanding -> ” But the keywords or formula goes down to every child element of the parent and select matching elements”

instead of using iterate through can it also be explained like above, is that also right according to my understanding?

]]>
By: Kesavan https://css-tricks.com/almanac/selectors/n/nth-child/#comment-1605568 Wed, 14 Dec 2016 12:16:44 +0000 http://css-tricks.com/?page_id=14230#comment-1605568 In reply to Marc Smitham.

Hi Experts,

I am trying to write a piece of CSS code to format the table in SAP Design Studio tool. In one of the table i have a CSS to hover the specific column of the table based on the n-th child selector. Below is the snippet.

.Table1 .sapzencrosstab-RowHeaderArea:hover tr > td:nth-child(4)
{
text-decoration: underline !important;
cursor: pointer !important;
}

Is it possible to mention the name of the column header here instead of fixing it as the 4th column. The requirement is to hover the column name called, say ‘Region’, instead of saying it as 4th column because Region dimension can change its position in the table when the user drills down few other dimensions into the table.

I have searched in forum to find out the css classes and possible workarounds, but could not find any.

Thanks & Regards,
Kesavan.

]]>
By: Marc Smitham https://css-tricks.com/almanac/selectors/n/nth-child/#comment-1605391 Sun, 04 Dec 2016 16:55:11 +0000 http://css-tricks.com/?page_id=14230#comment-1605391 Thank you for the concise explanation of the nth-child pseudo-class. Very helpful- it clears up a lot about this powerful selector. I’m comfortable enough with it now to start using it.

]]>