You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

嵌套SCSS编译正常但浏览器不生效?与选择器数量有关

嵌套SCSS编译后CSS规则被浏览器忽略的问题

我使用了如下嵌套SCSS选择器:

.entry-content > p,
.entry-content > .wp-block-buttons {
    + .wp-block-columns,
    + .wp-block-media-text {
        margin-top:3rem;
   }
}

它能正确编译为:

.entry-content > p + .wp-block-columns,
.entry-content > p + .wp-block-media-text,
.entry-content > .wp-block-buttons + .wp-block-columns,
.entry-content > .wp-block-buttons + .wp-block-media-text {
  margin-top: 3rem;
}

但这些规则被Chrome和Firefox完全忽略——在Chrome DevTools的Elements面板中,它们并非被其他规则覆盖,而是完全不存在。但点击DevTools里的样式表源文件,这些规则明确存在。我已清除服务器和浏览器缓存,也通过CSS验证工具检查过,均无问题。

若取消嵌套,直接将编译后的写法放入同一样式表,规则就能正常生效。


更新:疑似选择器数量引发的问题

之前简化了示例,完整SCSS规则如下:

.entry-content > ul,
.entry-content > ol,
.entry-content > h2,
.entry-content > h3,
.entry-content > h4,
.entry-content > h5,
.entry-content > p {
        + .wp-block-columns,
        + .wp-block-media-text {
            margin-top:3rem;
       }
    }

我逐个移除父选择器测试,发现当父选择器只剩3个时,规则就能生效。嵌套的选择器数量无限制,但父选择器超过3个时,浏览器就完全不加载该规则。

我困惑的是:编译后的CSS是正确的,样式表后续的其他样式也能正常显示,这是内存问题吗?

内容的提问来源于stack exchange,提问作者LBF

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 01:10:13