H1.js
export default styled.h1`
margin: 0px;
color: white;
`;
我想更改此组件的颜色,并且尝试了
import H1 from "./H1";
const ColoredH1 = styled(H1)`
color: "black"
`;
但这不会改变H1的颜色吗?
答案 0 :(得分:2)
答案 1 :(得分:1)
放入color: black
而不是color: "black"
import H1 from "./H1";
const ColoredH1 = styled(H1)`
color: black;
`;
供您理解
const Button = styled.button`
color: red;
font-size: 1em;
margin: 1em;
padding: 0.25em 1em;
border: 2px solid red;
border-radius: 3px;
`;
const CoralButton = styled(Button)`
color: coral;
border-color: coral;
`;
render(
<div>
<Button>Normal Button</Button>
<CoralButton>Tomato Button</CoralButton>
</div>
);