1

Given this scss

.root {

  color: red;

  &-child {
    color: blue;

    small & {
      font-size: 80%;
    }

  }

}

This is the CSS I get:

.root {
  color: red;
}
.root-child {
  color: blue;
}
small .root-child {
  font-size: 80%;
}

I want to style .root-child on small differently so the rule I need is:

small.root-child {
  font-size: 80%;
}

(Notice no whitespace after small)

How can I do that?

2 Answers 2

2

You need to use @at-root and that will remove the white space in your selector, as well as it will be a valid syntax so no issues while you try to compile.

.root {
  color: red;

  &-child {
    color: blue;

    @at-root small#{&} {
      font-size: 80%;
    }
  }
}
Sign up to request clarification or add additional context in comments.

Comments

1

You can use @at-root like this:

SCSS

.root {

  color: red;

  &-child {
    color: blue;

      @at-root {
        small#{&} {
             font-size: 80%;
        }
      }

  }

}

Compiled:

.root {
  color: red;
}
.root-child {
  color: blue;
}
small.root-child {
  font-size: 80%;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.