Tim*_* B. 6 css reactjs css-modules next.js
假设在我的global.css
Next.js 项目文件中我有:
.flex {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
}
Run Code Online (Sandbox Code Playgroud)
我还有一个Layout.js
组件和一个Layout.module.css
文件。该组件如下所示:
import styles from "../styles/Layout.module.css";
const Layout = ({ children }) => {
return (
<div>
<div className={styles.navbar}>
<div className="flex">
<h1>Structured Safety</h1>
<nav>
<ul>
<li> <a href="#">Home</a> </li>
<li> <a href="#">Demo</a> </li>
</ul>
</nav>
</div>
</div>
</div>
);
};
export default Layout;
Run Code Online (Sandbox Code Playgroud)
是Layout.module.css
:
/* Navbar */
.navbar {
background-color: var(--primary-color);
color: #fff;
height: 70px;
}
.navbar ul {
display: flex;
}
.navbar .flex {
justify-content: space-between;
}
Run Code Online (Sandbox Code Playgroud)
像这样的结构, my.navbar .flex
不会覆盖全局.flex
类并将. 如何实现从该组件样式覆盖我的全局样式?h1
nav
jul*_*ves 17
由于.flex
引用的是全局类,因此您需要使用:global
选择器在 CSS 模块中定位它。
/* Layout.module.css */
.navbar :global(.flex) {
justify-content: space-between;
}
Run Code Online (Sandbox Code Playgroud)
或者使用替代语法。
.navbar {
:global {
.flex {
justify-content: space-between;
}
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
11651 次 |
最近记录: |