【问题标题】:How to style not-hashed class in css modules file?如何在 css 模块文件中设置非散列类的样式?
【发布时间】:2022-01-17 06:41:53
【问题描述】:

我正在使用 css 模块,并且我有一个包含两个类的 React 组件:

  • 一个 - 使用 css 模块进行哈希处理
  • 另一个 - 没有散列,因为它来自另一个函数(假设它是“clear-class”)。
<div className={`${styles.hashedClass} clear-class`}>
   qwerty
</div>

我的 scss 文件看起来像这样,但它不工作。

.hashedClass {
  ...

  &.clear-class {
    background-color: green;
  }
}

当我使用开发工具查看源代码时,我注意到 clear-class 也被散列了。

有没有办法在 scss 文件中标记我想将样式应用于非散列类?

【问题讨论】:

    标签: css css-modules


    【解决方案1】:

    在你不想散列的类中使用:global()选择器

    .hashedClass {
      ...
    
      & :global(.clear-class) {
        background-color: green;
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2018-11-17
      • 2022-12-04
      • 2021-03-19
      • 2017-04-26
      • 2019-10-26
      • 2021-07-15
      • 2016-05-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多