Skip to content

Tailwind style modifiers like hover: and md: throw errors when no error present #1574

@rogadev

Description

@rogadev

Describe the bug

When I try to do the following:

<style lang="postcss">
  .nav-item {
    @apply px-4 py-2 text-gray-600 hover:text-gray-900 hover:bg-gray-100 text-2xl md:text-xl font-semibold;
  }
</style>

My IDE throws an error at the first occurrence of : in the string.
image

It seems that Svelte thinks this is a "css-syntax-error", however the lang property on my style block is clearly set to "postcss". Furthermore, Tailwind is correctly handling and applying these styles. You can even see that the Tailwind CSS extension is picking up that this is a hover modifier and displays the correct tooltip accordingly.
image

Reproduction

  1. Follow this Tailwind CSS guide to set up a Svelte project and configure Tailwind CSS.
  2. Create the following component and put it in your main view.
<header class="block md:flex md:justify-between md:items-center">
  <a
    id="brand-link"
    href="/"
    class="flex items-center justify-between md:justify-start"
  >
    <img
      id="brand-logo"
      src="/img/viu_logo.svg"
      alt="VIU Logo"
      class="h-[70px]"
    />
    <h1
      id="brand-title"
      class="font-extrabold text-3xl text-center mx-auto md:text-left md:ml-4"
    >
      Career Outlook Tool
    </h1>
  </a>

  <nav aria-label="Main" class="text-xl md:text-2xl">
    <ul
      class="flex gap-4 items-center mr-4 justify-evenly md:justify-start mt-4 md:mt-0 text-center"
    >
      <!-- <li class="nav-item"><a href="/outlook/2175">X</a></li> -->
      <li class="nav-item"><a href="/careers/search">Search Credentials</a></li>
      <li class="nav-item">
        <a href="/careers/by-program">Search Program</a>
      </li>
    </ul>
  </nav>
</header>

<style lang="postcss">
  .nav-item {
    @apply px-4 py-2 text-gray-600 hover:text-gray-900 hover:bg-gray-100 text-2xl md:text-xl font-semibold;
  }
</style>

Your IDE should yell at you.

Expected behaviour

No error message on the modifiers that use a : colon after the TailwindCSS @apply directive.

System Info

  • OS:
    • Edition Windows 10 Education
    • Version 21H2
    • Installed on ‎2020-‎08-‎27
    • OS build 19044.1826
    • Experience Windows Feature Experience Pack 120.2212.4180.0
  • IDE:
    • Version: 1.69.2 (user setup)
    • Commit: 3b889b090b5ad5793f524b5d1d39fda662b96a2a
    • Date: 2022-07-18T16:12:52.460Z
    • Electron: 18.3.5
    • Chromium: 100.0.4896.160
    • Node.js: 16.13.2
    • V8: 10.0.139.17-electron.0
    • OS: Windows_NT x64 10.0.19044
  • Extension:
    • Tailwind CSS IntelliSense v0.8.6

Which package is the issue about?

Svelte for VS Code extension

Additional Information, eg. Screenshots

I am making an educated guess that Svelte for VS Code is the source of the error message. Disabling, the error disappears. Enabling, it returns.

Most importantly, the steps in the error message do not solve the issue. I went so far as to follow the steps to install and configure Stylelint, to no avail.

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationquestionA user question

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions