选择器“:global .class"不是纯的(纯选择器必须至少包含一个本地类或 id) [英] Selector ":global .class" is not pure (pure selectors must contain at least one local class or id)

查看:33
本文介绍了选择器“:global .class"不是纯的(纯选择器必须至少包含一个本地类或 id)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I am using css modules with Sass in next.js and I got this error

:global {
    .slick-track {
        display: flex; // Syntax error: Selector ":global .slick-track" is not pure (pure selectors must contain at least one local class or id)
    }
}

This is as identical as the official css-modules doc example but with Sass instead of Less but in Sass syntax this should be working.

I saw this question but it was using a tag whereas I am using a class so it should be pure.

When I add () to :global it won't pop error but the style is not applying (You cannot find this style in browser console)

:global() {
    .slick-track {
        display: flex; // No error, but style not working
    }
}

For this scss file it does not have any dependency (@import @use etc.) but I think it is not the case.

I try adding a custom postcss.config.js according to this but not working either.

解决方案

You need to use global selector inside your local selector in CSS-modules.

For example, if you have HTML:

<div className={classes.someCSSMoludesClass}>
  <div className="some-global-class">
    content
  </div>
</div>

for rewriting global class "some-global-class" you need to make this inside your CSS-module:

.someCSSModulesClass {
  :global(.some-global-class) {
    %your properties%
  }
}

Don't forget to use selector inside :global.

I had the same problem, but in swiper slider, and resolved it like this. Maybe you have to write this class in the component that is above

这篇关于选择器“:global .class"不是纯的(纯选择器必须至少包含一个本地类或 id)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆