[英]Nesting styles ignores the styled component's styling
I'm using styled-components via cdn.我正在通过 cdn 使用样式组件。 If I do not nest styles, my components are styled.如果我不嵌套 styles,我的组件就会有样式。 If I try to nest, none of the styles take effect.如果我尝试嵌套,styles 都不会生效。
const AComponent = () => {
return (
<StyledComponent>
<p>Some Text</p>
</StyledComponent>
)
}
// using this shows a red background color
const StyledComponent = styled.div`
background-color: red;
`
// using this doesn't style anything - not even a red background color
const StyledComponent = styled.div`
background-color: red;
p {
color: black;
}
`
I tried with a bit of twist and found the below code working.我稍微尝试了一下,发现下面的代码有效。
export const StyledComponent = styled.div`
background-color: red;
& > p {
color: green;
}
`;
Here is the supporting link for explanation https://github.com/styled-components/styled-components/issues/330这是解释的支持链接https://github.com/styled-components/styled-components/issues/330
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.