【发布时间】:2021-04-30 21:38:24
【问题描述】:
- 我正在使用带有 Material-UI 作为框架的 Next.js。
- 我有 Layout 组件,它使用 Material-UI
<Container>包装内容。 - 我想覆盖限制背景宽度的 Layout 样式,使背景扩展到全屏。
components/Layout.js
import { Container } from '@material-ui/core';
export default function Layout({ children }) {
return <Container>{children}</Container>;
}
pages/_app.js
import Layout from '../components/Layout';
...
<Layout>
<Component {...pageProps} />
</Layout>
...
pages/index.js
export default function App() {
return (
<div style={{ backgroundColor: "yellow" }}>
Home Page
</div>
)
}
在大多数情况下使用 Layout 组件会派上用场,但有时我确实想从子组件中覆盖某些样式的 Layout。
在这种情况下,如何覆盖设置 maxWidth 限制的 Layout 组件的样式?
我尝试在 pages/index.js 的样式中添加{width: '100vw'},但没有成功。
任何帮助将不胜感激。
【问题讨论】:
-
看起来
Layout组件不接受除儿童以外的任何道具。获取所有道具并将它们传递给Container元素。({ children, ...restProps })然后像这样在Container中传播...restProps,<Container {...restProps}>
标签: css reactjs material-ui next.js