I have a particular component that looks like this:
const pretty = styled.div`
--nth-child: 5n;
--size: 20px; //css variable
width: var(--size);
&:nth-child(var(--nth-child)) {
//...styles...
}
@media (max-width: 768px) {
//overriding
--size: 12px;
--nth-child: 3n;
}
`
The main question I'm facing is how to interpolate the CSS variable in this specific location?
&:nth-child(var(--nth-child)) {
//...styles...
}
As far as I can tell, it seems impossible, so I'm looking for an alternative solution.
Please note: Using JavaScript variables is not an option in my situation.
Update:
The editor also highlights an error in that section:
https://i.sstatic.net/lb4W5.png
I attempted a workaround by trying this, but unfortunately, it didn't work either:
&:nth-child(${css`var(--nth-child)`}) {
margin-right: 0;
}