lit-analyzer icon indicating copy to clipboard operation
lit-analyzer copied to clipboard

lit-plugin complains about media queries in <style> tags

Open WickyNilliams opened this issue 2 years ago • 2 comments

consider a template like:

html`
  <style>
    @media (min-width: 768px) { /* (1) */
      body {
        color: red;
      } /* (2) */
    } 
  </style>
`

lit-plugin reports the following errors:

  1. { expected lit-plugin(no-invalid-css)
  2. at-rule or selector expected lit-plugin(no-invalid-css)

despite this being valid css

WickyNilliams avatar May 16 '22 13:05 WickyNilliams

Why aren't you using the css tagged template literal?

static styles = css`
   @media (min-width: 768px) {
      body {
        color: red;
      }
    } 
`;

https://lit.dev/docs/components/styles/

ba55ie avatar May 19 '22 08:05 ba55ie

The example given is a reduced test case for illustrative purposes only. I have experienced this issue in tests where I'm writing fixtures, and also cases where you need dynamic styles (as described here https://lit.dev/docs/components/styles/#style-element). So css doesn't cut it

WickyNilliams avatar May 19 '22 08:05 WickyNilliams