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.

Prepending a selector using @at-root fails with multiple parent selectors

See original GitHub issue

Not sure if this is intended, but would prefer @at-root be applied to each parent selector:

SCSS

.parent {
  &:hover,
  &:focus,
  &:active {
    .child {
      @at-root .ROOT#{&} {
        content: 'Only the first selector gets “.ROOT” instead of all of them';
      }
    }
  }
}

CSS

.ROOT.parent:hover .child,
.parent:focus .child,
.parent:active .child {
  content: 'Only the first selector gets “.ROOT” instead of all of them';
}

http://www.sassmeister.com/gist/f5b5db378086086f047570700621b506

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5

github_iconTop GitHub Comments

7reactions
chriseppsteincommented, Sep 8, 2016

Sass provides functions for working with selectors. Use this instead:

.parent {
  &:hover,
  &:focus,
  &:active {
    .child {
      @at-root #{selector-append(".ROOT", &)} {
        content: 'Only the first selector gets “.ROOT” instead of all of them';
      }
    }
  }
}
0reactions
Julix91commented, Aug 14, 2018

@bichotll - I think you’d have to have some code that applies to these selectors except the .ROOT

I for one am ecstatic to have found that this exists 😃 Looking forward to playing with it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ampersand (parent selector) inside nested selectors [duplicate]
Unfortunately, it's not currently possible in SASS (or any other CSS preprocessor I know of). Share.
Read more >
Parent Selector - Sass
When a parent selector is used in an inner selector, it's replaced with the corresponding outer selector. This happens instead of the normal...
Read more >
Features In-Depth | Less.js
It can be useful to prepend a selector to the inherited (parent) selectors. This can be done by putting the & after current...
Read more >
The Sass Ampersand - CSS-Tricks
The & always refers to the parent selector when nesting. Think of the & as being removed and replaced with the parent selector....
Read more >
Parent Reference - CSS PREprocessors
Selector prepend. Appending selectors might work when you are appending a class, id, or attribute selector, but what if we need to add...
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