你好,我也是新手,也是样式的新手:) 我正在尝试使用样式化组件来样式化Material-ui Button组件
我通过覆盖全局类名来做到这一点,我知道material-ui引入了诸如MuiButton-root等的全局类名
我不清楚在父选择器中使用“&” ,例如:
const StyledButton = styled(Button)`
&.MuiButton-root {
width: 500px;
}
.MuiButton-label {
color: ${props => props.labelColor};
justify-content: center;
}
`;
上面的代码有效,并且可以实现以下目的:
- 按钮的宽度为500px
- 标签为红色(labelColor作为属性传递)
- 请参见下面的沙箱以获取完整代码
问题: 为什么我不需要MuiButton根的“&”选择器,而不需要MuiButton根的标签?
这也是用样式化组件样式化Material-ui的最佳方法吗?