【发布时间】:2020-06-09 22:43:27
【问题描述】:
我想覆盖 Button 组件样式,但它不起作用。你能告诉我如何覆盖它还是应该将所有样式都赋予子按钮组件?
Button.js
const StyledButton = styled.button`
color: white;
background-color: yellow;
`;
const Button = ({text}) => {
return <StyledButton>{text}</StyledButton>;
};
export default Button;
父.js
import Button from "./Button";
const OverrideButton = styled(Button)`
&& {
color: blue;
background-color: green;
}
`;
const Parent = () => {
return <OverrideButton text="Parent" />;
};
【问题讨论】:
-
尝试在父组件中为 css 保留
!important