【问题标题】:How to make CSS grid working in react with CSS modules stylesheet如何使 CSS 网格与 CSS 模块样式表一起工作
【发布时间】:2021-07-03 19:18:07
【问题描述】:

我们有一个定义了网格的 css 文件,它之前工作正常。最近我们正在尝试使用 CSS 模块并将文件名从 sonar-landing-page.css 更改为 sonar-landing-page.module.css 并将其导入js 文件,如下面的代码示例,然后它停止工作,css 模块本身似乎工作正常,因为我们添加了一个简单的 .error 样式,如下所示,红色显示正确,但它是只是电网不工作,任何人都可以点亮一些灯吗?谢谢!

sonar-landing-page.module.css

.sonar-landing-wrapper {
    display: grid;
    grid-gap: 2rem;
    justify-items: stretch;
    align-items: stretch;
    grid-template-columns: repeat(6, 1fr);
    grid-column-gap: 5px;
    grid-auto-flow: row;
}

.sonar-history-job-table {
    grid-row: 2;
    grid-column: 1 / 7;
}
// test style I added to test if the css module itself is working
.error {
   color: red;
}

sonar-landing-page.js

import styles from './sonar-landing-page.module.css'

export default function SonarLandingPage() {
   return (
      <div className={styles.sonarLandingWrapper}>
        <div className={styles.sonarNewJobButton}>
           ...
        </div>
      </div>
   )
}

【问题讨论】:

    标签: css reactjs css-grid css-modules react-css-modules


    【解决方案1】:

    编写你在组件中使用的 CSS 样式 例如 .sonar-landing-wrapper ---> .sonarLandingWrapper

    .sonarLandingWrapper {
        display: grid;
        grid-gap: 2rem;
        justify-items: stretch;
        align-items: stretch;
        grid-template-columns: repeat(6, 1fr);
        grid-column-gap: 5px;
        grid-auto-flow: row;
    }
    
    .sonarHistoryJobTable {
        grid-row: 2;
        grid-column: 1 / 7;
    }
    // test style I added to test if the css module itself is working
    .error {
       color: red;
    }

    【讨论】:

    • 救命!也感谢您的回答!
    猜你喜欢
    • 2021-02-11
    • 1970-01-01
    • 2021-12-29
    • 2013-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-10
    • 2019-12-12
    相关资源
    最近更新 更多