Skip to content

[css-nesting?] Allow nesting @media inside @font-face #11940

@valtlai

Description

@valtlai

Spec: https://drafts.csswg.org/css-nesting/#conditionals (?)

Could we allow nesting @media at-rules inside @font-face?

My use case would be conditionally loading a hinted or unhinted font:

@font-face {
  font-family: 'The Font';
  src: url(the-font-hinted.woff2);

  @media (resolution >= 2x) {
    src: url(the-font-unhinted.woff2);
  }
}

Without nesting support (or if() support, see #11941), we have to needlessly repeat the unchanged descriptors:

@media (resolution < 2x) {
  @font-face {
    font-family: 'The Font';
    src: url(the-font-hinted.woff2);
  }
}

@media (resolution >= 2x) {
  @font-face {
    font-family: 'The Font';
    src: url(the-font-unhinted.woff2);
  }
}

This isn’t DRY and is annoying when there are a lot of @font-face rules.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions