Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
tedw opened this issue Sep 6, 2016 · 6 comments
Closed

Comments

@tedw
Copy link

tedw commented Sep 6, 2016

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

@chriseppstein
Copy link

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';
      }
    }
  }
}

@chriseppstein
Copy link

More selector functions are documented here: http://sass-lang.com/documentation/Sass/Script/Functions.html#selector_functions

@tedw
Copy link
Author

tedw commented Sep 8, 2016

@chriseppstein Oh, awesome, thanks!

@bichotll
Copy link

bichotll commented Apr 3, 2017

@chriseppstein out of curiosity...what's the use of at-root in that case then?

@Julix91
Copy link

Julix91 commented 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.

@eddkalosha
Copy link

eddkalosha commented Jan 3, 2023

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';
      }
    }
  }
}

you may try simply

@at-root .ROOT & { your child element code here… }

This is working fine for me for multiple selectors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants