mirror of
https://github.com/microsoft/vscode.git
synced 2026-08-25 10:25:41 +01:00
1.3 KiB
1.3 KiB
description, applyTo
| description | applyTo |
|---|---|
| CSS best practices for selector performance and maintainable state styling. Use when writing or reviewing CSS. | **/*.css |
CSS Best Practices
Selectors
- Avoid
:has()selectors. Because their result depends on descendant state, DOM mutations can invalidate styles on ancestors and cause expensive style recalculation, especially when selectors are broadly scoped. Instead, represent the state explicitly with a class or data attribute on the smallest container you own, and scope selectors to that marker. Add and remove the marker together with the state it represents. - Never match the
classattribute by substring ([class*="…"],[class^="…"],[class$="…"]). A single such selector anywhere in the workbench stylesheet defeats Blink's per-class invalidation: everyclassListchange then forces a style recalculation for that element, even when no rule references the class that changed. Measured on a 3.7k-node workbench, the ten[class*="monaco-decoration-itemColor"]selectors in the Modern UI tab styles alone made a full style recalculation 2.4x slower. When a class carries a generated suffix, have the code that applies it also set a stable marker class (seeDECORATION_LABEL_COLOR_CLASS) and match that instead.