简体   繁体   English

功能组件中的样式化组件不会将样式应用于组件

[英]styled components in functional component does not apply style to component

import React from 'react';
import styled from 'styled-components';
import { Typography } from 'antd';
const { Title } = Typography;
const StyledTitle = styled(Title)`
    align-self: center;
    color: rgb(140, 140, 140);
`;
export function Header(props : {children : React.ReactNode}) {
    return <StyledTitle>{props.children}</StyledTitle>;
}
export default Header;

I want to change text color to rgb(140, 140, 140) .我想将文本颜色更改为rgb(140, 140, 140) However color does not changed.但是颜色没有改变。

标题

I use Header component in other component like below.我在其他组件中使用Header组件,如下所示。

import { Header } from './Header';
export function Login() {
    return(
        <Container>
            <Header>Login</Header>
        </Container>
    );
}

if I set background-color: yellow;如果我设置background-color: yellow; , it applied well. , 它应用得很好。

标题

Because of this, I am confused.正因为如此,我很困惑。 Some styles are working and other styles are not working...一些 styles 正在工作,而其他 styles 不工作......

Try this:尝试这个:

 color: rgb(140, 140, 140);important;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM