【发布时间】:2021-12-12 23:25:15
【问题描述】:
我不熟悉整个 react 和 MUI 样式的组件。现在我正在处理一个网格,我想为特定组件的所有子组件设置样式。我想做的是${Item1}:nth-child(3n-1),${Item2}:nth-child(3n-1),${Item3}:nth-child(3n-1),但它不是这样工作的:
const Grid = styled('div')(({ theme }) => ({
width: '100%',
height: '100%',
padding: 0,
display: 'grid',
gap: 0,
gridTemplateColumns: 'repeat(3,minmax(0,1fr))',
`${Item1}:nth-child(3n-1)`: {
backgroundColor: 'lightYellow'
},
gridTemplateColumns: 'repeat(3,minmax(0,1fr))',
`${Item2}:nth-child(3n-1)`: {
backgroundColor: 'lightGreen'
},
gridTemplateColumns: 'repeat(3,minmax(0,1fr))',
`${Item3}:nth-child(3n-1)`: {
backgroundColor: 'lightBlue'
}
}
const Item1 = styled('div')(({ theme }) => ({
...
}));
const Item2 = styled('div')(({ theme }) => ({
...
}));
const Item3 = styled('div')(({ theme }) => ({
...
}));
<Grid>
<Item1 />
<Item2 />
<Item3 />
<Item1 />
<Item2 />
<Item3 />
<Item1 />
<Item2 />
<Item3 />
<Grid>
【问题讨论】:
标签: css reactjs material-ui css-selectors styled-components