有没有一种方法可以用ReactJS中的Styled-Components中的样式覆盖Semantic-UI中的样式?

时间:2019-10-26 18:51:37

标签: reactjs redux semantic-ui styled-components semantic-ui-react

我在ReactJS中构建一个小项目,我想使用Semantic-UI(作为我网站的主要主题),并使用样式化组件覆盖其中的某些部分(例如,它是一些自定义CSS)。

当我尝试将它们导入同一组件时,我注意到样式化组件将使用我编写的某些样式,但不会使用所有样式(例如文本大小或某些边距)。

编辑 这是我尝试在组件中实现它们的方法:

import "semantic-ui-css/semantic.min.css";
import { Grid, Form, Segment, Button, Header, Message, Icon } from 'semantic-ui-react';
import { StyledRegister } from '../styles/StyledRegister';

class Register extends React.Component {

...

render() {    
 return (
   <StyledRegister>
     <Grid textAlign="center" verticalAlign="middle">
       <Grid.Column style={{ maxWidth: 450 }}>
         // Here's continue the long code of my register page including form ect...
       </Grid.Column>
      </Grid>
    </StyledRegister>

你们中的任何人是否有可能的想法,如果有的话,是否有适当的方法来实现?

1 个答案:

答案 0 :(得分:0)

具有语义ui的定制适应统计信息组件的示例:

import "semantic-ui-css/semantic.min.css";
import { StyledStatistic } from "./styledStatistic";

function App() {
  return (
    <div className="App">
      <StyledStatistic>
        <StyledStatistic.Value>5,550</StyledStatistic.Value>
        <StyledStatistic.Label>Downloads</StyledStatistic.Label>
      </StyledStatistic>
    </div>
  );
}
import styled from "styled-components";
import { Statistic } from "semantic-ui-react";

export const StyledStatistic = styled(Statistic)`
  padding: 2rem;
  display: flex !important;
  justify-content: center;

  &&& > .value {
    color: red;
  }
  &&& > .label {
    color: green;
  }
`;

请参阅:https://codesandbox.io/s/goofy-mestorf-go410