0

My target is to override css class in react. Already defined class has properties from css framework. I want to save that properties and to add some own new.

Html:

import styles from '../../css/style.scss';

export default class Class extends React.Component {

  constructor() {
    super();
  }

  render() {
    return (
      <div className="item">
        <div className="image">
          <img src="" />
        </div>
        <div className="content">
          <span className="header"><span>
        </div>
      </div>
      );
    }
};

Sass:

.item {
    .content {
        .header {
            text-transform: capitalize;
        }
    }
}
1
  • You are importing a scss file then showing "sass" ( that's scss syntax by the way). What are you usin to import, CSS modules? Commented Sep 21, 2016 at 22:28

2 Answers 2

1

You can use inline styles in reactjs to do this:-

import styles from '../../css/style.scss';

export default class Class extends React.Component {

  constructor() {
    super();
  }

  render() {

   const styles={
        'textTransform': 'capitalize';
        //define other properties here, use camel case(remember we are using Javascript)
    }

    return (
      <div className="item">
        <div className="image">
          <img src="" />
        </div>
        <div className="content">
          <span className="header" style={style}><span>
        </div>
      </div>
      );
    }
};
Sign up to request clarification or add additional context in comments.

2 Comments

I want to use sass, not to set inline styles
0

Use:

require("!style!css!sass!../../css/style.scss");

instead of:

import styles from '../../css/style.scss';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.