Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support CSS nesting #300

Closed
BenjaminAster opened this issue Oct 19, 2022 · 7 comments
Closed

Support CSS nesting #300

BenjaminAster opened this issue Oct 19, 2022 · 7 comments

Comments

@BenjaminAster
Copy link

The CSS Nesting Module 1 "introduces the ability to nest one style rule inside another, with the selector of the child rule relative to the selector of the parent rule. This increases the modularity and maintainability of CSS stylesheets". Chromium's "Implement css-nesting-1" issue is the second most starred CSS issue on Chromium Monorail. Chromium has just implemented experimental CSS nesting support and the CSSWG confirmed that the syntax will not change any more. Even though CSS nesting is not yet supported in any stable version of a mayor browser, it is already usable with a PostCSS plugin, and, as mentioned above, in Chrome Canary with experimental web platform features enabled.

Related issue on microsoft/vscode: #147824

@GauravB159
Copy link
Contributor

Is anyone working on this? I'm not sure how big a change it would be, but I'd love to contribute

@nilaallj
Copy link

nilaallj commented Nov 8, 2022

NB: Despite the claim that the current version of the CSS Nesting Module 1 is the final one, the spec got a new draft version published on October 28. That seems to be the version Chrome Canary uses.

The main difference in the draft version is that the @nest rule has been dropped in favour of operators (>, ~ and +) and selector characters (., # and :), meaning that the ampersand is only necessary when a nested selector does not begin with its parent selector. This is quite a significant change from the earlier version.

A separate PostCSS plugin has been released for the new spec.

Since the latest version of the spec is still in draft stage, this is probably not the right time to start working on an implementation in VS Code. However, since nesting likely will radically change how many developers write CSS, this should definitely not be slept on once it reaches the stable browsers.

@samwillis
Copy link

CSS Nesting was shipped in Chrome 112 which will be going stable next week (29th March).

It is also in the current Safari Tech Preview.

All indications are the spec is final with it being in both Chrome and highly likely to ship in the next stable Safari.

@romainmenke
Copy link
Contributor

I think this is done, but maybe I overlooked something in #345

Maybe ok to close and people can report anything missing as a new issue?

@altrusl
Copy link

altrusl commented Jan 14, 2024

CSS nesting works in VS Code but syntax highlighting is broken

Helmut888 added a commit to Helmut888/vscode-css-languageservice that referenced this issue Jan 24, 2024
Helmut888 added a commit to Helmut888/vscode-css-languageservice that referenced this issue Jan 24, 2024
Helmut888 added a commit to Helmut888/vscode-css-languageservice that referenced this issue Jan 24, 2024
Helmut888 added a commit to Helmut888/vscode-css-languageservice that referenced this issue Jan 24, 2024
Helmut888 added a commit to Helmut888/vscode-css-languageservice that referenced this issue Jan 24, 2024
@Stan-Stani
Copy link

Stan-Stani commented Feb 19, 2024

Shouldn't nesting of a keyframe have an error highlight? I was scratching my head for a long time until I tried it without nesting and it worked in Chrome and Firefox.

.App {
  background: darkolivegreen;

  .description {
    overflow-y: auto;
    height: 125px;
  }

  .result {
    height: 1.5em;
    opacity: 0;
  }

  @keyframes anim {
    from {
      opacity: 0;
    }
    to {
      opacity: 1;
    }
  }

  .fadeIn {
    animation-name: anim;
    animation-duration: 10s;
    animation-timing-function: ease-in;
    animation-fill-mode: forwards;
  }
}

@aeschli
Copy link
Contributor

aeschli commented Mar 22, 2024

Closing as nesting is implemented in this service. VS Code still has highlight issues but that's unrelated to the service.

@Stan-Stani You can file a separate issue, but in general we are very tolerant when validating, leaving it to linters to do the full validation. Correctly validating CSS is quite challenging, and users don't like false positives

@aeschli aeschli closed this as completed Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants