1
votes

I've recently switched to using styled-components for my styling and I've been trying to get the @supports feature of CSS to work but with no luck.

The @supports syntax is used somewhat like:

@supports (display: grid) {
    .Container {
        background-color: orange;
    }
}

Now this is fine as the styled-components docs have the following line:

Note: Ampersands (&) get replaced by our generated, unique classname for that styled component

But when I try using the ampersand to use this, it doesn't work. When using the below code I get an ampersand in the outputted CSS

const Container = styled.div`
    @supports (display: block) {
      & {
        background-color: seagreen;
      }
    }
`;
1

1 Answers

6
votes

This seems to be a genuine bug in styled-components! You should not need to put the ampersand there at all, it should work just like media queries:

const Container = styled.div`
  @supports (display: block) {
    background-color: seagreen;
  }
`;

It doesn't right now though, so I've opened an issue with our parser and it should hopefully be resolved soon. I'll update this answer once it's fixed!