Why doesn't CSS nesting appended nesting selector work within pseudoselectors? - Stack Overflow

Why is the first div red, but not the other? If you enable SCSS preprocessor in the pen, both divs are

Why is the first div red, but not the other? If you enable SCSS preprocessor in the pen, both divs are red as expected.

.regular {
  html & {
    color: red;
  }
}

.pseudo:before {
  content: '(pseudo) style me red';

  html & {
    color: red;
  }
}
<div class="regular">(regular) style me red</div>

<div class="pseudo"></div>

Why is the first div red, but not the other? If you enable SCSS preprocessor in the pen, both divs are red as expected.

https://codepen.io/aeharding/pen/wvVLBZg

.regular {
  html & {
    color: red;
  }
}

.pseudo:before {
  content: '(pseudo) style me red';

  html & {
    color: red;
  }
}
<div class="regular">(regular) style me red</div>

<div class="pseudo"></div>

Share Improve this question edited Nov 20, 2024 at 7:49 Temani Afif 274k28 gold badges365 silver badges485 bronze badges asked Nov 20, 2024 at 7:45 aehardingaeharding 5981 gold badge4 silver badges18 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 2

It's by design but it may change in the future: https://github/w3c/csswg-drafts/issues/7433

From the actual Specification:

The nesting selector cannot represent pseudo-elements

.regular {
  html & {
    color: red;
  }
}

.pseudo:before {
  content: '(pseudo) style me red';

  html & {
    color: red;
  }
}
<div class="regular">(regular) style me red</div>

<div class="pseudo"></div>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742373996a4431821.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信