Nested css selectors

From rogie/figui3 · View interactive version

Nested css selectors is an AI agent skill from the GitHub repository rogie/figui3. Implements CSS nesting and advanced selectors with progressive enhancement and maintainable specificity. Use when writing or refactoring nested CSS, or when the user mentions :has, :is, :where, :not, or complex selector composition.

How to use this skill

Skill file

Nested CSS + Selectors

Purpose

Write modern, readable CSS using nesting and selector composition without breaking fallback behavior or creating specificity traps.

Core Rules

  1. Start with a stable baseline rule first.
  2. Use nesting to improve readability, not to increase selector depth.
  3. Keep selector chains short; avoid deeply coupled DOM paths.
  4. Prefer low-specificity patterns (:where(...)) for reusable component styles.
  5. Gate risky/brand-new behavior behind @supports selector(...) when needed.

Nesting Guidelines

.card {
  padding: 12px;

  &__title {
    font-weight: 600;
  }

  &:hover {
    background: var(--figma-color-bg-secondary);
  }
}

Advanced Selector Guidelines

.field :is(input, select, textarea) {
  font: inherit;
}

.panel :where(button, [role="button"]) {
  cursor: pointer;
}

Progressive Enhancement Pattern

/* baseline behavior */
.form-row {
  border: 1px solid var(--figma-color-border);
}

/* enhanced behavior only where supported */
@supports selector(.form-row:has(input:focus-visible)) {
  .form-row:has(input:focus-visible) {
    border-color: var(--figma-color-border-selected);
  }
}

Specificity Guardrails

Refactor Workflow

  1. Identify repeated selector/declaration blocks.
  2. Consolidate with :is(...) or :where(...) where intent matches.
  3. Introduce nesting inside the owning component block.
  4. Recheck specificity effects (especially when replacing comma groups).
  5. Verify hover/focus/disabled/error states are unchanged.

Quick Checklist

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.