Add option to use -nth-child as little as possible
See original GitHub issueHi,
I have the problem that your library falls back to something like this: :nth-child(11) > :nth-child(2) > :nth-child(1) > :nth-child(9)
but what I need is a selector that goes as far as possible without using :nth-child, i.e. like this one: div#__next > div.styles__MainContent-ghnxum-0.iIIhTW > div.styles__ContainerRoot-evpclk-2.kowoAH:nth-child(9)
because all the nth-child-numbers change during the pageload.
So the feature request would be to make as long selectors as possible without using nth-child. This is perfect for me but it outputs a selector matching multiple elements 😦
I have tried those configuration options for your utility but it still prefers shortness over a sustainably working selector:
whitelist: ['class', 'tag', 'id', 'attribute'],
combineWithinSelector: true,
combineBetweenSelectors: true,
includeTag: true
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:5 (2 by maintainers)
Top Results From Across the Web
nth-child - CSS-Tricks
Rather than adding a class to every fourth item (e.g. .last ), we can use :nth-child : .module:nth-child(4n) { margin-right: 0; }.
Read more >nth-child() - CSS: Cascading Style Sheets - MDN Web Docs
Note that, in the element:nth-child() syntax, the child count includes children of any element type; but it is considered a match only if ......
Read more >CSS nth-child for greater than and less than - Stack Overflow
In this case, . container:nth-child(2) won't select the 2nd div. container element (which has 5th content).
Read more >CSS nth child Selectors - YouTube
When you are trying to target HTML elements in a pattern, like every second or third list item or table row, then the...
Read more >How to use :nth-child in CSS. The - JTWay
The :nth-child pseudo-class allows to select one and more elements based on their source order.. “How to use :nth-child in CSS” is published...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I would like this too. Also I would like to be able to say that certain selectors are basically mandatory if they are available. e.g. if a document has only one
<link>
element, then asking for the selector for it just returnslink
, which is no use at all if later on someone adds another link. Having an option something likemandatory: ["[href]", "[src]"]
to require the use of those attributes if they exist would be very helpful.@jribbens I’m closing this issue. What you describe in your comments seem to be out of scope of the original issue.
If what you describe still a thing for you, please open a new issue and describe in more detail how it should work and how the library should know when to add unnecessary parts of the selector. Thank you.