Skip to content

[selectors-4] Allow * before a type selector #8253

@tabatkins

Description

@tabatkins

I was gonna wait to propose this until after the Nesting issue resolved, but I think it might be useful to bring up earlier now.

The restriction currently imposed by the Nesting spec is that you can't start your selector with an ident. If your selector is a descendant-combinator relative selector, this is easy to fix - rather than div {...} write & div {...}. But if you're adding context to your parent rule, like div & {...}, the fix isn't as easy - you have to write :is(div) & {...} to trigger the correct parsing.

On Twitter, Brandon McConnell suggested an easy fix - you can currently prepend a * to any compound selector for absolutely no effect, unless the compound selector contains a type selector. That is, .foo and *.foo are precisely identical in behavior, but *div is currently invalid. (Effectively, * is a wildcard type selector right now.)

Brandon suggests making that valid, so you can add a * to any compound selector. Then the easiest fix for any nested selector that starts with an ident is to just put a * at the front of it. div {...} can become *div {...}, div & {...} can become *div & {...}, etc. And putting a * in front of anything else is already valid and doesn't change the meaning, so this works well as a generic "just spam it if you want to be safe" technique, if people don't want to learn the rule.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Closed as RetractedWhen the person who raised the issue thinks that there's no issue after all.css-nesting-1Current Workselectors-4Current Work

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions