小编Bre*_*Man的帖子

nth-child() 无法与材料 UI 配合使用

我试图使用 nth-child 使两个段落具有不同的背景颜色。对于 JSX 我有

<div className={classes.paragraphs}>
    <p>Test 1</p>
    <p>Test 2</p>
</div>
Run Code Online (Sandbox Code Playgroud)

对于我的CSS

const useStyles = makeStyles(() => ({

  paragraphs: {
    backgroundColor: "blue",
    "&:nth-child(1)": {
       backgroundColor: "green"
    }
  }
}));
Run Code Online (Sandbox Code Playgroud)

使用此 CSS,两个段落都有蓝色背景,但第一个段落应该有绿色背景。

css material-ui

1
推荐指数
1
解决办法
3876
查看次数

标签 统计

css ×1

material-ui ×1