最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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>

发布评论

评论列表(0)

  1. 暂无评论