question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BUG: Using _odd does not work like CSS nth-child(odd)

See original GitHub issue

🐛 Bug report

When I used _odd and instead of nth-child(odd) CSS selector, I’ve seen unexpected behaviours in the UI.

💥 Steps to reproduce

  1. Go to http://github.com/ogzhanolguncu/ogzhanolguncu.com/blob/master/components/TimeLineItem.tsx and clone this repo
  2. Find line number 22 and try adding _odd={{ left: "auto", right:"5px" }} By adding _odd, you will override existing CSS and break the solution.

🧐 Expected behaviour

_odd does not behave like an nth-child(odd)

🧭 Possible Solution

Not compulsory, but suggesting a fix would be great!

🌍 System information

Software Version(s)
Chakra UI v1
Browser Chrome
Operating System Windows

📝 Additional information

When CSS is used that’s the outcome:

withcss

With _odd

withodd

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
nihalanisumitcommented, Feb 8, 2021

okay now applying the nth-of-type selector to all the children of the right-side-bar and this seems to be working for me. This is for anyone struggling to find a css solution.

<Box className=“right-side-bar” … > … </Box>

.right-side-bar > *:nth-of-type(odd) {
    background: #f6f6f6;
  }

  .right-side-bar > *:nth-of-type(even) {
    background: #e9e9e9;
  }
0reactions
with-heartcommented, Feb 8, 2021

I don’t have an answer to your question about SSR unfortunately, but I wanted to thank you for following up with a solution @nihalanisumit. Much appreciated that you’d think of others that might come later with a similar problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

nth-child(odd) not working as expected - Stack Overflow
You should be setting ClientTableRow class, like so: .ClientTableRow:nth-child(odd) {background-color:#FF0000;}.
Read more >
Forums - CSS - :nth-child/nth-of-type bug - CSS-Tricks
Right, but my problem is that the list item is there and needs to be there. There will be elements in the list...
Read more >
A :nth-child(An+B [of S]?) polyfill thanks to CSS :has() and :not()
This selector is mostly used to select the odd or even elements from a group of siblings, or to alternate the style of...
Read more >
Odd & Even :nth-child Selectors not working - SitePoint
Hey Gang, I've got a peculiar problem. I'm using :nth-child(odd) and :nth-child(even) selectors on some div's with the class "tour-box".
Read more >
How can I style every other row in a dynamic table? - Litmus
I am using this CSS code to target evert odd <tr> element (see img ... the inliner doesn't like (odd) so could try...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found