1

I am using react to build simple app, and using Materilize css. In my UserProfile Component class importing UserProfile.css import "./UserProfile.css.

/* UserProfile.css */ 

.custom-class {
  margin-top: 30 !important;
  color: pink;
}

UserProfile in render method have

<h1 className="custom-class">Title</h1> // Margin is not applyed, but color is pink

I have an option to

<h1 style={{ marginTop: 30, color: "pink" }}>Title</h1> 

this works fine, but I prefer style code in css files.

I am not sure maybe that issue has no relation to overriding.

4
  • 4
    Hello, you should use px in css files please change your code tomargin-top: 30px !important; and try again Commented Jul 31, 2019 at 13:46
  • @octobus YES, Stupid me, thanks a lot Commented Jul 31, 2019 at 13:49
  • Believe me it happens a lot, don't worry :) I also post an answer. Good luck with your project. Commented Jul 31, 2019 at 13:53
  • @octobus Thanks. I don't know, do I have to delete question(cause the issue has no relation with overriding)? Commented Jul 31, 2019 at 13:59

3 Answers 3

1

you should use px in css files, change your code to margin-top: 30px !important; and it should work.

And if you want to check overriding issues in css, you can inspect your code(with right click your browser and choose inspect) and check if its crossed or not.

Sign up to request clarification or add additional context in comments.

Comments

1

You'll need to use camelCase for your classname, so .customClass instead of .custom-class.

Then your import statement should look like:

import css from './UserProfile.css`;

and in your component:

<h1 className={css.customClass}>Title</h1>

Read up on CSS Modules for more information.

Comments

0

You don't have a unit for margin-top in your css class

.custom-class {
  margin-top: 30px !important;
  color: pink;
}

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.