question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Spec for the @at-root directive

See original GitHub issue

I’d like to nail down the exact spec for how @at-root will work.

So here’s some test cases:

inline selector mode

.foo { @at-root .bar { color: gray; } }
.bar { color: gray; }

& still works when not in script mode

.foo { @at-root .bar & { color: gray; } }
.bar .foo { color: gray; }

& works when in script mode

.foo { @at-root .bar #{&} { color: gray; } }
.bar .foo { color: gray; }

@at-root can take a block

.foo { @at-root { .bar #{&} { color: gray; } } }
.bar .foo { color: gray; }

@at-root blocks only affect the nearest child selectors.

.foo { @at-root { .bar { .baz { color: gray; } } } }
.bar .baz { color: gray; }

@at-root doesn’t remove selectors from directives by default.

@media print {
  @supports ( transform-origin: 5% 5% ) {
    .foo {
      @at-root {
        .bar #{&} {
          color: gray; } } } } }
@media print { @supports ( transform-origin: 5% 5% ) { .bar .foo { color: gray; } } }

@at-root in block form can remove a selector from all directives.

@media print {
  @supports ( transform-origin: 5% 5% ) {
    .foo {
      @at-root without-directives {
        .bar #{&} {
          color: gray; } } } } }
.bar .foo { color: gray; }

@at-root in block form can remove a selector from specific directives.

Media:

@media print {
  @supports ( transform-origin: 5% 5% ) {
    .foo {
      @at-root without-media {
        .bar #{&} {
          color: gray; } } } } }
@supports ( transform-origin: 5% 5% ) { .bar .foo { color: gray; } }

Supports:

@media print {
  @supports ( transform-origin: 5% 5% ) {
    .foo {
      @at-root without-supports {
        .bar #{&} {
          color: gray; } } } } }
@media print { .bar .foo { color: gray; } }

Several directives removed:

@media print {
  @supports ( transform-origin: 5% 5% ) {
    .foo {
      @at-root without-supports, without-media {
        .bar #{&} {
          color: gray; } } } } }
.bar .foo { color: gray; }

Selector inheritance uses the resulting selector and directive context.

%outside-the-media-block { color: gray }
@media print {
  @supports ( transform-origin: 5% 5% ) {
    .foo {
      @at-root without-directives {
        .bar #{&} {
          // not an error because the directives were removed.
          @extend %outside-the-media-block;  } } } } }
.bar .foo { color: gray; }

In theory we can make without-xxx be agnostic of directive type, but this may have issues with prefixed directives. Or we can have a whitelist of directive names.

The cases around directive removal will solve a big problem with the limitations around using @extend within media blocks. Specifically, this allows you to extend a selector via a mixin for all media contexts instead of just within the current media block.

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:25 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
davestewartcommented, Jun 3, 2014

Yeah, an @at-node(n) construct to traverse back up the selector tree would be great. I’ve needed that a few times.

1reaction
nex3commented, May 28, 2013

@at-root without-whatever is syntactically ambiguous with the @at-root <selector> syntax. If we’re going to add flags like that, I think we’d need to find a better syntax for it. One possibility is using the !important flag syntax, as in @at-root !without-supports.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sass - At-root Directives
Sass - At-root Directives, The @at-root directive is a collection of nested rules which is able to make the style block at root...
Read more >
Sass @At rules and directives
This blog will discuss Sass @At rules and directives in detail. We will cover @use, @function, @debug, @at-root, @forward, ...
Read more >
Quick Configuration Guide — mod_wsgi 4.9.4 documentation
WSGI is a specification of a generic API for mapping between an underlying web ... This directive can only appear in the main...
Read more >
at-root
The @at-root rule is necessary here because Sass doesn't know what interpolation was used to generate a selector when it's performing selector nesting....
Read more >
OASIS Naming Directives
For example: "Working Draft 01" and "Committee Specification Draft 02", ... for a particular release, or for the Work Product at root level....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found